diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php
index b56279b5..5e1f4f37 100644
--- a/PHPCI/Model/Base/ProjectBase.php
+++ b/PHPCI/Model/Base/ProjectBase.php
@@ -36,6 +36,7 @@ class ProjectBase extends Model
'id' => null,
'title' => null,
'reference' => null,
+ 'branch' => null,
'ssh_private_key' => null,
'ssh_public_key' => null,
'type' => null,
@@ -200,17 +201,15 @@ class ProjectBase extends Model
}
/**
- * Get the value of Branch / branch.
- *
- * @return string
- */
+ * 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'];
- }
+ $rtn = $this->data['branch'];
+
+ return $rtn;
}
/**
@@ -365,6 +364,7 @@ class ProjectBase extends Model
*/
public function setBranch($value)
{
+ $this->_validateNotNull('Branch', $value);
$this->_validateString('Branch', $value);
if ($this->data['branch'] === $value) {
diff --git a/PHPCI/Model/Project.php b/PHPCI/Model/Project.php
index 55df01c5..9047de02 100644
--- a/PHPCI/Model/Project.php
+++ b/PHPCI/Model/Project.php
@@ -58,4 +58,18 @@ class Project extends ProjectBase
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'];
+ }
+ }
}
diff --git a/PHPCI/Service/ProjectService.php b/PHPCI/Service/ProjectService.php
index 26954ddc..1ab24aae 100644
--- a/PHPCI/Service/ProjectService.php
+++ b/PHPCI/Service/ProjectService.php
@@ -76,6 +76,10 @@ class ProjectService
$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:
$this->processAccessInformation($project);
diff --git a/Tests/PHPCI/Model/ProjectTest.php b/Tests/PHPCI/Model/ProjectTest.php
new file mode 100644
index 00000000..367eaa77
--- /dev/null
+++ b/Tests/PHPCI/Model/ProjectTest.php
@@ -0,0 +1,78 @@
+
+ */
+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());
+ }
+}
diff --git a/Tests/PHPCI/Service/ProjectServiceTest.php b/Tests/PHPCI/Service/ProjectServiceTest.php
index 146eb97c..abb06d8f 100644
--- a/Tests/PHPCI/Service/ProjectServiceTest.php
+++ b/Tests/PHPCI/Service/ProjectServiceTest.php
@@ -49,6 +49,7 @@ class ProjectServiceTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('Test Project', $returnValue->getTitle());
$this->assertEquals('github', $returnValue->getType());
$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',
'allow_public_status' => 1,
'build_config' => 'config',
+ 'branch' => 'testbranch',
);
$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('public', $returnValue->getSshPublicKey());
$this->assertEquals('config', $returnValue->getBuildConfig());
+ $this->assertEquals('testbranch', $returnValue->getBranch());
$this->assertEquals(1, $returnValue->getAllowPublicStatus());
}
diff --git a/phpunit.xml b/phpunit.xml
index 0e1d6810..78685417 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -20,6 +20,9 @@
./Tests/PHPCI/Plugin
+
+ ./Tests/PHPCI/Model
+
./Tests/PHPCI/Service