Skip to content

Commit 02c4f1e

Browse files
committed
Merged in khoweengage/bitbucket-api/refsbranches (pull request #31)
Updated Repository to support API v2.0 branches GET
2 parents ae3cb1d + f057d58 commit 02c4f1e

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitbucket-api package.
5+
*
6+
* (c) Alexandru G. <alex@gentle.ro>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Bitbucket\API\Repositories\Refs;
13+
14+
use Bitbucket\API;
15+
16+
/**
17+
* @author Kevin Howe <kjhowe@gmail.com>
18+
*/
19+
class Branches extends API\Api
20+
{
21+
/**
22+
* Get a list of branches
23+
*
24+
* @access public
25+
* @param string $account The team or individual account owning the repository.
26+
* @param string $repo The repository identifier.
27+
* @return MessageInterface
28+
*/
29+
public function all($account, $repo)
30+
{
31+
return $this->getClient()->setApiVersion('2.0')->get(
32+
sprintf('repositories/%s/%s/refs/branches', $account, $repo)
33+
);
34+
}
35+
36+
/**
37+
* Get an individual branch
38+
*
39+
* @access public
40+
* @param string $account The team or individual account owning the repository.
41+
* @param string $repo The repository identifier.
42+
* @param string $name The branch identifier.
43+
* @return MessageInterface
44+
*/
45+
public function get($account, $repo, $name)
46+
{
47+
return $this->getClient()->setApiVersion('2.0')->get(
48+
sprintf('repositories/%s/%s/refs/branches/%s', $account, $repo, $name)
49+
);
50+
}
51+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Bitbucket\Tests\API\Repositories\Refs;
4+
5+
use Bitbucket\Tests\API as Tests;
6+
7+
class BranchesTest extends Tests\TestCase
8+
{
9+
public function testAll()
10+
{
11+
$endpoint = 'repositories/gentle/eof/refs/branches';
12+
$expectedResult = json_encode('dummy');
13+
14+
$client = $this->getHttpClientMock();
15+
$client->expects($this->once())
16+
->method('get')
17+
->with($endpoint)
18+
->will($this->returnValue($expectedResult));
19+
20+
$repository = $this->getClassMock('Bitbucket\API\Repositories\Refs\Branches', $client);
21+
22+
/** @var $repository \Bitbucket\API\Repositories\Refs\Branches */
23+
$actual = $repository->all('gentle', 'eof');
24+
25+
$this->assertEquals($expectedResult, $actual);
26+
}
27+
28+
public function testGet()
29+
{
30+
$endpoint = 'repositories/gentle/eof/refs/branches/abranch';
31+
$expectedResult = json_encode('dummy');
32+
33+
$client = $this->getHttpClientMock();
34+
$client->expects($this->once())
35+
->method('get')
36+
->with($endpoint)
37+
->will($this->returnValue($expectedResult));
38+
39+
$repository = $this->getClassMock('Bitbucket\API\Repositories\Refs\Branches', $client);
40+
41+
/** @var $repository \Bitbucket\API\Repositories\Refs\Branches */
42+
$actual = $repository->get('gentle', 'eof', 'abranch');
43+
44+
$this->assertEquals($expectedResult, $actual);
45+
}
46+
}

0 commit comments

Comments
 (0)