2015-03-28 13:04:28 +01:00
|
|
|
<?php
|
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
namespace Tests\PHPCensor\Command;
|
2015-03-28 13:04:28 +01:00
|
|
|
|
2016-08-11 16:32:42 +02:00
|
|
|
use PHPCensor\Command\CreateBuildCommand;
|
2015-03-28 13:04:28 +01:00
|
|
|
use Symfony\Component\Console\Application;
|
|
|
|
use Symfony\Component\Console\Tester\CommandTester;
|
|
|
|
|
2017-07-24 08:45:52 +02:00
|
|
|
class CreateBuildCommandTest extends \PHPUnit\Framework\TestCase
|
2015-03-28 13:04:28 +01:00
|
|
|
{
|
|
|
|
/**
|
2016-07-21 19:20:59 +02:00
|
|
|
* @var \PHPCensor\Command\CreateAdminCommand|\PHPUnit_Framework_MockObject_MockObject
|
2015-03-28 13:04:28 +01:00
|
|
|
*/
|
|
|
|
protected $command;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Symfony\Component\Console\Application|\PHPUnit_Framework_MockObject_MockObject
|
|
|
|
*/
|
|
|
|
protected $application;
|
|
|
|
|
2016-08-11 16:32:42 +02:00
|
|
|
public function setUp()
|
2015-03-28 13:04:28 +01:00
|
|
|
{
|
2016-08-11 16:32:42 +02:00
|
|
|
parent::setUp();
|
2015-03-28 13:04:28 +01:00
|
|
|
|
2017-01-09 17:23:29 +01:00
|
|
|
$projectMock = $this->getMockBuilder('PHPCensor\\Model\\Project')->getMock();
|
2015-03-28 13:04:28 +01:00
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
$projectStoreMock = $this->getMockBuilder('PHPCensor\\Store\\ProjectStore')
|
2015-03-28 13:04:28 +01:00
|
|
|
->getMock();
|
|
|
|
$projectStoreMock->method('getById')
|
2016-04-21 09:46:38 +02:00
|
|
|
->will($this->returnValueMap([
|
|
|
|
[1, 'read', $projectMock],
|
|
|
|
[2, 'read', null],
|
|
|
|
]));
|
2015-03-28 13:04:28 +01:00
|
|
|
|
2016-07-19 20:28:11 +02:00
|
|
|
$buildServiceMock = $this->getMockBuilder('PHPCensor\\Service\\BuildService')
|
2015-03-28 13:04:28 +01:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2016-08-11 16:32:42 +02:00
|
|
|
|
2015-03-28 13:04:28 +01:00
|
|
|
$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]
|
2015-03-28 13:04:28 +01:00
|
|
|
);
|
|
|
|
|
2016-08-11 16:32:42 +02:00
|
|
|
$this->command = new CreateBuildCommand($projectStoreMock, $buildServiceMock);
|
2015-03-28 13:04:28 +01:00
|
|
|
|
|
|
|
$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');
|
2015-03-28 13:04:28 +01:00
|
|
|
$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']);
|
2015-03-28 13:04:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
2015-06-25 16:21:23 +02:00
|
|
|
public function testExecuteWithUnknownProjectId()
|
2015-03-28 13:04:28 +01:00
|
|
|
{
|
|
|
|
$commandTester = $this->getCommandTester();
|
2016-04-21 09:46:38 +02:00
|
|
|
$commandTester->execute(['projectId' => 2]);
|
2015-03-28 13:04:28 +01:00
|
|
|
}
|
|
|
|
}
|