Fixing some issues with project default branches, adding tests for that too

This commit is contained in:
Dan Cryer 2014-07-14 14:59:04 +01:00
parent 2bff0270cf
commit cb53ec9c6d
6 changed files with 111 additions and 9 deletions

View file

@ -36,6 +36,7 @@ class ProjectBase extends Model
'id' => null, 'id' => null,
'title' => null, 'title' => null,
'reference' => null, 'reference' => null,
'branch' => null,
'ssh_private_key' => null, 'ssh_private_key' => null,
'ssh_public_key' => null, 'ssh_public_key' => null,
'type' => null, 'type' => null,
@ -200,17 +201,15 @@ class ProjectBase extends Model
} }
/** /**
* Get the value of Branch / branch. * Get the value of Branch / branch.
* *
* @return string * @return string
*/ */
public function getBranch() public function getBranch()
{ {
if (empty($this->data['branch'])) { $rtn = $this->data['branch'];
return $this->getType() === 'hg' ? 'default' : 'master';
} else { return $rtn;
return $this->data['branch'];
}
} }
/** /**
@ -365,6 +364,7 @@ class ProjectBase extends Model
*/ */
public function setBranch($value) public function setBranch($value)
{ {
$this->_validateNotNull('Branch', $value);
$this->_validateString('Branch', $value); $this->_validateString('Branch', $value);
if ($this->data['branch'] === $value) { if ($this->data['branch'] === $value) {

View file

@ -58,4 +58,18 @@ class Project extends ProjectBase
return $rtn; return $rtn;
} }
/**
* Get the value of Branch / branch.
*
* @return string
*/
public function getBranch()
{
if (empty($this->data['branch'])) {
return $this->getType() === 'hg' ? 'default' : 'master';
} else {
return $this->data['branch'];
}
}
} }

View file

@ -76,6 +76,10 @@ class ProjectService
$project->setAllowPublicStatus((int)$options['allow_public_status']); $project->setAllowPublicStatus((int)$options['allow_public_status']);
} }
if (array_key_exists('branch', $options)) {
$project->setBranch($options['branch']);
}
// Allow certain project types to set access information: // Allow certain project types to set access information:
$this->processAccessInformation($project); $this->processAccessInformation($project);

View file

@ -0,0 +1,78 @@
<?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\Model\Tests;
use PHPCI\Model\Project;
/**
* Unit tests for the ProjectService class.
* @author Dan Cryer <dan@block8.co.uk>
*/
class ProjectTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
}
/**
* @covers PHPUnit::execute
*/
public function testExecute_TestGitDefaultBranch()
{
$project = new Project();
$project->setType('git');
$this->assertEquals('master', $project->getBranch());
}
/**
* @covers PHPUnit::execute
*/
public function testExecute_TestGithubDefaultBranch()
{
$project = new Project();
$project->setType('github');
$this->assertEquals('master', $project->getBranch());
}
/**
* @covers PHPUnit::execute
*/
public function testExecute_TestGitlabDefaultBranch()
{
$project = new Project();
$project->setType('gitlab');
$this->assertEquals('master', $project->getBranch());
}
/**
* @covers PHPUnit::execute
*/
public function testExecute_TestBitbucketDefaultBranch()
{
$project = new Project();
$project->setType('bitbucket');
$this->assertEquals('master', $project->getBranch());
}
/**
* @covers PHPUnit::execute
*/
public function testExecute_TestMercurialDefaultBranch()
{
$project = new Project();
$project->setType('hg');
$this->assertEquals('default', $project->getBranch());
}
}

View file

@ -49,6 +49,7 @@ class ProjectServiceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('Test Project', $returnValue->getTitle()); $this->assertEquals('Test Project', $returnValue->getTitle());
$this->assertEquals('github', $returnValue->getType()); $this->assertEquals('github', $returnValue->getType());
$this->assertEquals('block8/phpci', $returnValue->getReference()); $this->assertEquals('block8/phpci', $returnValue->getReference());
$this->assertEquals('master', $returnValue->getBranch());
} }
/** /**
@ -61,6 +62,7 @@ class ProjectServiceTest extends \PHPUnit_Framework_TestCase
'ssh_public_key' => 'public', 'ssh_public_key' => 'public',
'allow_public_status' => 1, 'allow_public_status' => 1,
'build_config' => 'config', 'build_config' => 'config',
'branch' => 'testbranch',
); );
$returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', $options); $returnValue = $this->testedService->createProject('Test Project', 'github', 'block8/phpci', $options);
@ -68,6 +70,7 @@ class ProjectServiceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('private', $returnValue->getSshPrivateKey()); $this->assertEquals('private', $returnValue->getSshPrivateKey());
$this->assertEquals('public', $returnValue->getSshPublicKey()); $this->assertEquals('public', $returnValue->getSshPublicKey());
$this->assertEquals('config', $returnValue->getBuildConfig()); $this->assertEquals('config', $returnValue->getBuildConfig());
$this->assertEquals('testbranch', $returnValue->getBranch());
$this->assertEquals(1, $returnValue->getAllowPublicStatus()); $this->assertEquals(1, $returnValue->getAllowPublicStatus());
} }

View file

@ -20,6 +20,9 @@
<testsuite name="PHPCI Plugin Test Suite"> <testsuite name="PHPCI Plugin Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Plugin</directory> <directory suffix="Test.php">./Tests/PHPCI/Plugin</directory>
</testsuite> </testsuite>
<testsuite name="PHPCI Model Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Model</directory>
</testsuite>
<testsuite name="PHPCI Service Test Suite"> <testsuite name="PHPCI Service Test Suite">
<directory suffix="Test.php">./Tests/PHPCI/Service</directory> <directory suffix="Test.php">./Tests/PHPCI/Service</directory>
</testsuite> </testsuite>