Skip to content

Commit

Permalink
Add tests for branch name of PR builds
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 7, 2020
1 parent 43738e1 commit 258293f
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Ci/Bamboo.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public function getGitCommit(): string

public function getGitBranch(): string
{
// TODO: While the PR source branch is in `bamboo.repository_pr_sourceBranch`, it cannot be reliably
// used, probably because it is environment variables with dot in name.
// As a result, returned branch in case of PR build is the target branch (eg. master) not the PR branch.

return $this->env->getString('bamboo_planRepository_branch');
}

Expand Down
6 changes: 5 additions & 1 deletion tests/phpt/Ci/CiDetector_BambooPullRequest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bamboo_shortJobKey=JOB1
bamboo_shortJobName=Default Job
bamboo_shortPlanKey=foo
bamboo_shortPlanName=Plan Name
bamboo.repository_pr_sourceBranch=foobar
bamboo.repository_pr_sourceBranch=pr-branch
bamboo.repository_pr_targetBranch=branch-name

--FILE--
Expand All @@ -44,7 +44,11 @@ require __DIR__ . '/../../../vendor/autoload.php';
$ci = (new OndraM\CiDetector\CiDetector())->detect();
echo "Is pull request:\n";
var_dump($ci->isPullRequest()->describe());
echo "Git branch:\n";
var_dump($ci->getGitBranch());

--EXPECT--
Is pull request:
string(3) "Yes"
Git branch:
string(11) "branch-name"
4 changes: 4 additions & 0 deletions tests/phpt/Ci/CiDetector_CirclePullRequest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ require __DIR__ . '/../../../vendor/autoload.php';
$ci = (new OndraM\CiDetector\CiDetector())->detect();
echo "Is pull request:\n";
var_dump($ci->isPullRequest()->describe());
echo "Git branch:\n";
var_dump($ci->getGitBranch());

--EXPECT--
Is pull request:
string(3) "Yes"
Git branch:
string(13) "test-circleci"
4 changes: 4 additions & 0 deletions tests/phpt/Ci/CiDetector_CodeshipPullRequest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ require __DIR__ . '/../../../vendor/autoload.php';
$ci = (new OndraM\CiDetector\CiDetector())->detect();
echo "Is pull request:\n";
var_dump($ci->isPullRequest()->describe());
echo "Git branch:\n";
var_dump($ci->getGitBranch());

--EXPECT--
Is pull request:
string(3) "Yes"
Git branch:
string(13) "test-codeship"
4 changes: 4 additions & 0 deletions tests/phpt/Ci/CiDetector_ContinuousphpPullRequest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ require __DIR__ . '/../../../vendor/autoload.php';
$ci = (new OndraM\CiDetector\CiDetector())->detect();
echo "Is pull request:\n";
var_dump($ci->isPullRequest()->describe());
echo "Git branch:\n";
var_dump($ci->getGitBranch());

--EXPECT--
Is pull request:
string(3) "Yes"
Git branch:
string(25) "test-continuousphp-branch"
4 changes: 4 additions & 0 deletions tests/phpt/Ci/CiDetector_DronePullRequest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ require __DIR__ . '/../../../vendor/autoload.php';
$ci = (new OndraM\CiDetector\CiDetector())->detect();
echo "Is pull request:\n";
var_dump($ci->isPullRequest()->describe());
echo "Git branch:\n";
var_dump($ci->getGitBranch());

--EXPECT--
Is pull request:
string(3) "Yes"
Git branch:
string(10) "test-drone"
4 changes: 4 additions & 0 deletions tests/phpt/Ci/CiDetector_GitLabExternalPullRequest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ require __DIR__ . '/../../../vendor/autoload.php';
$ci = (new OndraM\CiDetector\CiDetector())->detect();
echo "Is pull request:\n";
var_dump($ci->isPullRequest()->describe());
echo "Git branch:\n";
var_dump($ci->getGitBranch());

--EXPECT--
Is pull request:
string(3) "Yes"
Git branch:
string(11) "test-gitlab"
4 changes: 4 additions & 0 deletions tests/phpt/Ci/CiDetector_GitLabMergeRequest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ require __DIR__ . '/../../../vendor/autoload.php';
$ci = (new OndraM\CiDetector\CiDetector())->detect();
echo "Is pull request:\n";
var_dump($ci->isPullRequest()->describe());
echo "Git branch:\n";
var_dump($ci->getGitBranch());

--EXPECT--
Is pull request:
string(3) "Yes"
Git branch:
string(11) "test-gitlab"

0 comments on commit 258293f

Please sign in to comment.