Initial work on adding a Services layer to PHPCI, for better testability. Starting with Projects
This commit is contained in:
parent
53bddf33a2
commit
af4cdd90b6
5 changed files with 244 additions and 25 deletions
15
Tests/PHPCI/Service/MockProjectStore.php
Normal file
15
Tests/PHPCI/Service/MockProjectStore.php
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\PHPCI\Service;
|
||||
|
||||
use b8\Model;
|
||||
use PHPCI\Store\ProjectStore;
|
||||
|
||||
class MockProjectStore extends ProjectStore
|
||||
{
|
||||
public function save(Model $project)
|
||||
{
|
||||
$project->setId(1);
|
||||
return $project;
|
||||
}
|
||||
}
|
||||
101
Tests/PHPCI/Service/ProjectServiceTest.php
Normal file
101
Tests/PHPCI/Service/ProjectServiceTest.php
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
<?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/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Service\Tests;
|
||||
|
||||
use PHPCI\Model\Project;
|
||||
use PHPCI\Service\ProjectService;
|
||||
use Tests\PHPCI\Service\MockProjectStore;
|
||||
|
||||
/**
|
||||
* Unit tests for the ProjectService class.
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class ProjectServiceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ProjectService $testedService
|
||||
*/
|
||||
protected $testedService;
|
||||
|
||||
/**
|
||||
* @var \ $mockProjectStore
|
||||
*/
|
||||
protected $mockProjectStore;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockProjectStore = new MockProjectStore();
|
||||
$this->testedService = new ProjectService($this->mockProjectStore);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPUnit::execute
|
||||
*/
|
||||
public function testExecute_CreateBasicProject()
|
||||
{
|
||||
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci');
|
||||
|
||||
$this->assertEquals('Test Project', $returnValue->getTitle());
|
||||
$this->assertEquals('github', $returnValue->getType());
|
||||
$this->assertEquals('block8/phpci', $returnValue->getReference());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPUnit::execute
|
||||
*/
|
||||
public function testExecute_CreateProjectWithOptions()
|
||||
{
|
||||
$options = array(
|
||||
'ssh_private_key' => 'private',
|
||||
'ssh_public_key' => 'public',
|
||||
'allow_public_status' => 1,
|
||||
'build_config' => 'config',
|
||||
);
|
||||
|
||||
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', $options);
|
||||
|
||||
$this->assertEquals('private', $returnValue->getSshPrivateKey());
|
||||
$this->assertEquals('public', $returnValue->getSshPublicKey());
|
||||
$this->assertEquals('config', $returnValue->getBuildConfig());
|
||||
$this->assertEquals(1, $returnValue->getAllowPublicStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* @link https://github.com/Block8/PHPCI/issues/484
|
||||
* @covers PHPUnit::execute
|
||||
*/
|
||||
public function testExecute_CreateGitlabProjectWithoutPort()
|
||||
{
|
||||
$reference = 'git@gitlab.block8.net:block8/phpci.git';
|
||||
$returnValue = $this->testedService->createProject('Gitlab', 'gitlab', $reference);
|
||||
|
||||
$this->assertEquals('git', $returnValue->getAccessInformation('user'));
|
||||
$this->assertEquals('gitlab.block8.net', $returnValue->getAccessInformation('domain'));
|
||||
$this->assertEquals('block8/phpci', $returnValue->getReference());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers PHPUnit::execute
|
||||
*/
|
||||
public function testExecute_UpdateExistingProject()
|
||||
{
|
||||
$project = new Project();
|
||||
$project->setTitle('Before Title');
|
||||
$project->setReference('Before Reference');
|
||||
$project->setType('github');
|
||||
|
||||
$returnValue = $this->testedService->updateProject($project, 'After Title', 'bitbucket', 'After Reference');
|
||||
|
||||
$this->assertEquals('After Title', $returnValue->getTitle());
|
||||
$this->assertEquals('After Reference', $returnValue->getReference());
|
||||
$this->assertEquals('bitbucket', $returnValue->getType());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue