Skip to content

Commit 251f088

Browse files
Joe Freshleafvimishor
Joe Freshleaf
authored andcommitted
Merged in freshleafmedia/bitbucket-api/feature/src-api-2.0 (pull request #45)
Updates Src get/raw to use bitbucket API 2.0
1 parent 1568c49 commit 251f088

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

docs/examples/repositories/src.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ $src->get($account_name, $repo_slug, '1e10ffe', 'app/models/');
2020
### Get raw content of an individual file:
2121

2222
```php
23-
$src->raw($account_name, $repo_slug, '1e10ffe', 'app/models/core.php');
23+
$src->get($account_name, $repo_slug, '1e10ffe', 'app/models/core.php');
2424
```
2525

2626
### Create file in repository

lib/Bitbucket/API/Repositories/Src.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
class Src extends API\Api
2525
{
2626
/**
27-
* Get a list of repo source
27+
* Get raw content of an individual file, or the contents of a directory
2828
*
2929
* @access public
3030
* @param string $account The team or individual account owning the repository.
@@ -35,28 +35,11 @@ class Src extends API\Api
3535
*/
3636
public function get($account, $repo, $revision, $path)
3737
{
38-
return $this->requestGet(
38+
return $this->getClient()->setApiVersion("2.0")->get(
3939
sprintf('repositories/%s/%s/src/%s/%s', $account, $repo, $revision, $path)
4040
);
4141
}
4242

43-
/**
44-
* Get raw content of an individual file
45-
*
46-
* @access public
47-
* @param string $account The team or individual account owning the repository.
48-
* @param string $repo The repository identifier.
49-
* @param string $revision A value representing the revision or branch to list.
50-
* @param string $path The path can be a filename or a directory path.
51-
* @return MessageInterface
52-
*/
53-
public function raw($account, $repo, $revision, $path)
54-
{
55-
return $this->requestGet(
56-
sprintf('repositories/%s/%s/raw/%s/%s', $account, $repo, $revision, $path)
57-
);
58-
}
59-
6043
/**
6144
* Create file in repository
6245
* $params contains the files to create, the key is the file (with path) to create and the value is the

test/Bitbucket/Tests/API/Repositories/SrcTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,35 @@ class SrcTest extends Tests\TestCase
1010
public function testListRepoSrc()
1111
{
1212
$endpoint = 'repositories/gentle/eof/src/1e10ffe//lib';
13-
$expectedResult = json_encode('dummy');
13+
$expectedResult = $this->fakeResponse(array('dummy'));
1414

15-
$src = $this->getApiMock('Bitbucket\API\Repositories\Src');
16-
$src->expects($this->once())
17-
->method('requestGet')
15+
$client = $this->getHttpClientMock();
16+
$client->expects($this->once())
17+
->method('get')
1818
->with($endpoint)
1919
->will( $this->returnValue($expectedResult) );
2020

2121
/** @var $src \Bitbucket\API\Repositories\Src */
22+
$src = $this->getClassMock('Bitbucket\API\Repositories\Src', $client);
2223
$actual = $src->get('gentle', 'eof', '1e10ffe', '/lib');
2324

2425
$this->assertEquals($expectedResult, $actual);
2526
}
2627

2728
public function testSrcGetRawContent()
2829
{
29-
$endpoint = 'repositories/gentle/eof/raw/1e10ffe/lib/Gentle/Bitbucket/API/Repositories/Services.php';
30-
$expectedResult = json_encode('dummy');
30+
$endpoint = 'repositories/gentle/eof/src/1e10ffe/lib/Gentle/Bitbucket/API/Repositories/Services.php';
31+
$expectedResult = $this->fakeResponse(array('dummy'));
3132

32-
$src = $this->getApiMock('Bitbucket\API\Repositories\Src');
33-
$src->expects($this->once())
34-
->method('requestGet')
33+
$client = $this->getHttpClientMock();
34+
$client->expects($this->once())
35+
->method('get')
3536
->with($endpoint)
3637
->will( $this->returnValue($expectedResult) );
3738

3839
/** @var $src \Bitbucket\API\Repositories\Src */
39-
$actual = $src->raw('gentle', 'eof', '1e10ffe', 'lib/Gentle/Bitbucket/API/Repositories/Services.php');
40+
$src = $this->getClassMock('Bitbucket\API\Repositories\Src', $client);
41+
$actual = $src->get('gentle', 'eof', '1e10ffe', 'lib/Gentle/Bitbucket/API/Repositories/Services.php');
4042

4143
$this->assertEquals($expectedResult, $actual);
4244
}
@@ -92,4 +94,4 @@ public function testSrcCreateBranch()
9294

9395
$src->create('gentle', 'eof', $params);
9496
}
95-
}
97+
}

0 commit comments

Comments
 (0)