Skip to content

Commit 8e732e9

Browse files
odi-umvimishor
authored andcommitted
Add refs endpoint from v2.0
Add `refs` endpoint from 2.0 to fetch both tags and branches in one call
2 parents 251f088 + 07a2aa0 commit 8e732e9

File tree

2 files changed

+85
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)