php-censor/tests/src/Service/ProjectServiceTest.php

121 lines
4 KiB
PHP
Raw Normal View History

<?php
2016-07-19 20:28:11 +02:00
namespace Tests\PHPCensor\Service;
2016-07-19 20:28:11 +02:00
use PHPCensor\Model\Project;
use PHPCensor\Service\ProjectService;
/**
* Unit tests for the ProjectService class.
2018-02-16 10:41:56 +01:00
*
* @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()
{
2017-01-09 17:23:29 +01:00
$this->mockProjectStore = $this->getMockBuilder('PHPCensor\Store\ProjectStore')->getMock();
$this->mockProjectStore->expects($this->any())
->method('save')
->will($this->returnArgument(0));
$this->testedService = new ProjectService($this->mockProjectStore);
}
public function testExecute_CreateBasicProject()
{
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', 0);
2018-02-16 10:41:56 +01:00
self::assertEquals('Test Project', $returnValue->getTitle());
self::assertEquals('github', $returnValue->getType());
self::assertEquals('block8/phpci', $returnValue->getReference());
self::assertEquals('master', $returnValue->getBranch());
}
public function testExecute_CreateProjectWithOptions()
{
2016-08-25 18:13:19 +02:00
$options = [
'ssh_private_key' => 'private',
'ssh_public_key' => 'public',
2018-03-09 19:00:53 +01:00
'allow_public_status' => true,
2016-08-25 18:13:19 +02:00
'build_config' => 'config',
'branch' => 'testbranch',
];
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', 0, $options);
2018-02-16 10:41:56 +01:00
self::assertEquals('private', $returnValue->getSshPrivateKey());
self::assertEquals('public', $returnValue->getSshPublicKey());
self::assertEquals('config', $returnValue->getBuildConfig());
self::assertEquals('testbranch', $returnValue->getBranch());
2018-03-09 19:00:53 +01:00
self::assertEquals(true, $returnValue->getAllowPublicStatus());
}
/**
* @link https://github.com/Block8/PHPCI/issues/484
*/
public function testExecute_CreateGitlabProjectWithoutPort()
{
$reference = 'git@gitlab.block8.net:block8/phpci.git';
$returnValue = $this->testedService->createProject('Gitlab', 'gitlab', $reference, 0);
2018-02-16 10:41:56 +01:00
self::assertEquals('git', $returnValue->getAccessInformation('user'));
self::assertEquals('gitlab.block8.net', $returnValue->getAccessInformation('domain'));
self::assertEquals('block8/phpci', $returnValue->getReference());
}
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');
2018-02-16 10:41:56 +01:00
self::assertEquals('After Title', $returnValue->getTitle());
self::assertEquals('After Reference', $returnValue->getReference());
self::assertEquals('bitbucket', $returnValue->getType());
}
public function testExecute_EmptyPublicStatus()
{
$project = new Project();
2018-03-09 19:00:53 +01:00
$project->setAllowPublicStatus(true);
2016-08-25 18:13:19 +02:00
$options = [
'ssh_private_key' => 'private',
2016-08-25 18:13:19 +02:00
'ssh_public_key' => 'public',
'build_config' => 'config',
];
$returnValue = $this->testedService->updateProject($project, 'Test Project', 'github', 'block8/phpci', $options);
2018-03-09 19:00:53 +01:00
self::assertEquals(false, $returnValue->getAllowPublicStatus());
}
public function testExecute_DeleteProject()
{
2017-01-09 17:23:29 +01:00
$store = $this->getMockBuilder('PHPCensor\Store\ProjectStore')->getMock();
$store->expects($this->once())
->method('delete')
->will($this->returnValue(true));
$service = new ProjectService($store);
$project = new Project();
2018-02-16 10:41:56 +01:00
self::assertEquals(true, $service->deleteProject($project));
}
}