Fixed namespaces (PHPCI -> PHPCensor)
This commit is contained in:
parent
60d74b0b44
commit
60a2b7282a
238 changed files with 1014 additions and 863 deletions
149
tests/PHPCensor/Service/BuildServiceTest.php
Normal file
149
tests/PHPCensor/Service/BuildServiceTest.php
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2014, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link https://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace Tests\PHPCensor\Service;
|
||||
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Model\Project;
|
||||
use PHPCensor\Service\BuildService;
|
||||
|
||||
/**
|
||||
* Unit tests for the ProjectService class.
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class BuildServiceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var BuildService $testedService
|
||||
*/
|
||||
protected $testedService;
|
||||
|
||||
/**
|
||||
* @var \ $mockBuildStore
|
||||
*/
|
||||
protected $mockBuildStore;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockBuildStore = $this->getMock('PHPCensor\Store\BuildStore');
|
||||
$this->mockBuildStore->expects($this->any())
|
||||
->method('save')
|
||||
->will($this->returnArgument(0));
|
||||
|
||||
$this->testedService = new BuildService($this->mockBuildStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPUnit::execute
|
||||
*/
|
||||
public function testExecute_CreateBasicBuild()
|
||||
{
|
||||
$project = new Project();
|
||||
$project->setType('github');
|
||||
$project->setId(101);
|
||||
|
||||
$returnValue = $this->testedService->createBuild($project);
|
||||
|
||||
$this->assertEquals(101, $returnValue->getProjectId());
|
||||
$this->assertEquals(Build::STATUS_NEW, $returnValue->getStatus());
|
||||
$this->assertNull($returnValue->getStarted());
|
||||
$this->assertNull($returnValue->getFinished());
|
||||
$this->assertNull($returnValue->getLog());
|
||||
$this->assertEquals(\PHPCensor\Helper\Lang::get('manual_build'), $returnValue->getCommitMessage());
|
||||
$this->assertNull($returnValue->getCommitterEmail());
|
||||
$this->assertNull($returnValue->getExtra());
|
||||
$this->assertEquals('master', $returnValue->getBranch());
|
||||
$this->assertInstanceOf('DateTime', $returnValue->getCreated());
|
||||
$this->assertEquals('Manual', $returnValue->getCommitId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPUnit::execute
|
||||
*/
|
||||
public function testExecute_CreateBuildWithOptions()
|
||||
{
|
||||
$project = new Project();
|
||||
$project->setType('hg');
|
||||
$project->setId(101);
|
||||
|
||||
$returnValue = $this->testedService->createBuild($project, '123', 'testbranch', 'test@example.com', 'test');
|
||||
|
||||
$this->assertEquals('testbranch', $returnValue->getBranch());
|
||||
$this->assertEquals('123', $returnValue->getCommitId());
|
||||
$this->assertEquals('test', $returnValue->getCommitMessage());
|
||||
$this->assertEquals('test@example.com', $returnValue->getCommitterEmail());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPUnit::execute
|
||||
*/
|
||||
public function testExecute_CreateBuildWithExtra()
|
||||
{
|
||||
$project = new Project();
|
||||
$project->setType('bitbucket');
|
||||
$project->setId(101);
|
||||
|
||||
$returnValue = $this->testedService->createBuild($project, null, null, null, null, ['item1' => 1001]);
|
||||
|
||||
$this->assertEquals(1001, $returnValue->getExtra('item1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPUnit::execute
|
||||
*/
|
||||
public function testExecute_CreateDuplicateBuild()
|
||||
{
|
||||
$build = new Build();
|
||||
$build->setId(1);
|
||||
$build->setProject(101);
|
||||
$build->setCommitId('abcde');
|
||||
$build->setStatus(Build::STATUS_FAILED);
|
||||
$build->setLog('Test');
|
||||
$build->setBranch('example_branch');
|
||||
$build->setStarted(new \DateTime());
|
||||
$build->setFinished(new \DateTime());
|
||||
$build->setCommitMessage('test');
|
||||
$build->setCommitterEmail('test@example.com');
|
||||
$build->setExtra(json_encode(['item1' => 1001]));
|
||||
|
||||
$returnValue = $this->testedService->createDuplicateBuild($build);
|
||||
|
||||
$this->assertNotEquals($build->getId(), $returnValue->getId());
|
||||
$this->assertEquals($build->getProjectId(), $returnValue->getProjectId());
|
||||
$this->assertEquals($build->getCommitId(), $returnValue->getCommitId());
|
||||
$this->assertNotEquals($build->getStatus(), $returnValue->getStatus());
|
||||
$this->assertEquals(Build::STATUS_NEW, $returnValue->getStatus());
|
||||
$this->assertNull($returnValue->getLog());
|
||||
$this->assertEquals($build->getBranch(), $returnValue->getBranch());
|
||||
$this->assertNotEquals($build->getCreated(), $returnValue->getCreated());
|
||||
$this->assertNull($returnValue->getStarted());
|
||||
$this->assertNull($returnValue->getFinished());
|
||||
$this->assertEquals('test', $returnValue->getCommitMessage());
|
||||
$this->assertEquals('test@example.com', $returnValue->getCommitterEmail());
|
||||
$this->assertEquals($build->getExtra('item1'), $returnValue->getExtra('item1'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPUnit::execute
|
||||
*/
|
||||
public function testExecute_DeleteBuild()
|
||||
{
|
||||
$store = $this->getMock('PHPCensor\Store\BuildStore');
|
||||
$store->expects($this->once())
|
||||
->method('delete')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$service = new BuildService($store);
|
||||
$build = new Build();
|
||||
|
||||
$this->assertEquals(true, $service->deleteBuild($build));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue