Skip to content

Commit 7e5dfc9

Browse files
committed
Refactor Dual Methods To Single, and Fix Test
- In order to match existing API conventions, the two method solution for branch/tag was consolidated into one method and extra data in the third argument. - Updated ReferencesTest.php to only test the single method
1 parent 8107e13 commit 7e5dfc9

File tree

2 files changed

+8
-36
lines changed

2 files changed

+8
-36
lines changed

lib/Github/Api/GitData/References.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,19 @@ public function all($username, $repository)
2626
}
2727

2828
/**
29-
* Get all matching references for a particular branch of a repository.
29+
* Get all matching references for the supplied reference name
3030
*
31-
* @param string $username
32-
* @param string $repository
33-
* @param string $branch
34-
*
35-
* @return array
36-
*/
37-
public function matchingBranch(string $username, string $repository, string $branch): array
38-
{
39-
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/matching-refs/heads/'.rawurlencode($branch));
40-
}
41-
42-
/**
43-
* Get all matching references for a particular branch of a repository.
31+
* https://developer.github.com/v3/git/refs/#list-matching-references
4432
*
4533
* @param string $username
4634
* @param string $repository
47-
* @param string $tag
35+
* @param string $reference
4836
*
4937
* @return array
5038
*/
51-
public function matchingTag(string $username, string $repository, string $tag): array
39+
public function matching(string $username, string $repository, string $reference): array
5240
{
53-
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/matching-refs/tags/'.rawurlencode($tag));
41+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/git/matching-refs/'.rawurlencode($reference));
5442
}
5543

5644
/**

test/Github/Tests/Api/GitData/ReferencesTest.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,17 @@ public function shouldGetAllRepoReferences()
7474
/**
7575
* @test
7676
*/
77-
public function shouldGetAllMatchingBranchRepoReferences()
77+
public function shouldGetAllMatchingReferences()
7878
{
7979
$expectedValue = [['reference' => 'some data']];
8080

8181
$api = $this->getApiMock();
8282
$api->expects($this->once())
8383
->method('get')
84-
->with('/repos/l3l0/l3l0repo/git/matching-refs/heads/branchName')
84+
->with('/repos/l3l0/l3l0repo/git/matching-refs/refName')
8585
->will($this->returnValue($expectedValue));
8686

87-
$this->assertEquals($expectedValue, $api->matchingBranch('l3l0', 'l3l0repo', 'branchName'));
88-
}
89-
90-
/**
91-
* @test
92-
*/
93-
public function shouldGetAllMatchingTagRepoReferences()
94-
{
95-
$expectedValue = [['reference' => 'some data']];
96-
97-
$api = $this->getApiMock();
98-
$api->expects($this->once())
99-
->method('get')
100-
->with('/repos/l3l0/l3l0repo/git/matching-refs/tags/tagName')
101-
->will($this->returnValue($expectedValue));
102-
103-
$this->assertEquals($expectedValue, $api->matchingTag('l3l0', 'l3l0repo', 'tagName'));
87+
$this->assertEquals($expectedValue, $api->matching('l3l0', 'l3l0repo', 'refName'));
10488
}
10589

10690
/**

0 commit comments

Comments
 (0)