php-censor/tests/PHPCensor/Command/CreateBuildCommandTest.php

87 lines
2.6 KiB
PHP
Raw Normal View History

<?php
/**
* PHPCI - Continuous Integration for PHP
*
* @copyright Copyright 2014, Block 8 Limited.
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
* @link http://www.phptesting.org/
*/
2016-07-19 20:28:11 +02:00
namespace Tests\PHPCensor\Command;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
class CreateBuildCommandTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPCI\Command\CreateAdminCommand|\PHPUnit_Framework_MockObject_MockObject
*/
protected $command;
/**
* @var \Symfony\Component\Console\Application|\PHPUnit_Framework_MockObject_MockObject
*/
protected $application;
public function setup()
{
parent::setup();
2016-07-19 20:28:11 +02:00
$projectMock = $this->getMock('PHPCensor\\Model\\Project');
2016-07-19 20:28:11 +02:00
$projectStoreMock = $this->getMockBuilder('PHPCensor\\Store\\ProjectStore')
->getMock();
$projectStoreMock->method('getById')
2016-04-21 09:46:38 +02:00
->will($this->returnValueMap([
[1, 'read', $projectMock],
[2, 'read', null],
]));
2016-07-19 20:28:11 +02:00
$buildServiceMock = $this->getMockBuilder('PHPCensor\\Service\\BuildService')
->disableOriginalConstructor()
->getMock();
$buildServiceMock->method('createBuild')
->withConsecutive(
2016-04-21 09:46:38 +02:00
[$projectMock, null, null, null, null, null],
[$projectMock, '92c8c6e', null, null, null, null],
[$projectMock, null, 'master', null, null, null]
);
2016-07-19 20:28:11 +02:00
$this->command = $this->getMockBuilder('PHPCensor\\Command\\CreateBuildCommand')
2016-04-21 09:46:38 +02:00
->setConstructorArgs([$projectStoreMock, $buildServiceMock])
->setMethods(['reloadConfig'])
->getMock();
$this->application = new Application();
}
protected function getCommandTester()
{
$this->application->add($this->command);
2016-07-21 19:02:11 +02:00
$command = $this->application->find('php-censor:create-build');
$commandTester = new CommandTester($command);
return $commandTester;
}
public function testExecute()
{
$commandTester = $this->getCommandTester();
2016-04-21 09:46:38 +02:00
$commandTester->execute(['projectId' => 1]);
$commandTester->execute(['projectId' => 1, '--commit' => '92c8c6e']);
$commandTester->execute(['projectId' => 1, '--branch' => 'master']);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testExecuteWithUnknownProjectId()
{
$commandTester = $this->getCommandTester();
2016-04-21 09:46:38 +02:00
$commandTester->execute(['projectId' => 2]);
}
}