Skip to content

Commit 3d8755a

Browse files
committed
Merge branch 'feature/api-v2-teams' into develop
2 parents 4ff7bb3 + cf71647 commit 3d8755a

File tree

4 files changed

+231
-0
lines changed

4 files changed

+231
-0
lines changed

docs/Home.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ A simple PHP wrapper for Bitbucket API.
2424
* [Services](repositories/services.md)
2525
* [Src](repositories/src.md)
2626
* [Wiki](repositories/wiki.md)
27+
* [Teams](teams.md) (API 2.0)
2728
* [User](user.md)
2829
* [Repositories](user/repositories.md)
2930
* [Users](users.md)

docs/teams.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Teams
2+
3+
----
4+
Get Team related information.
5+
6+
### Prepare:
7+
```php
8+
$team = new Bitbucket\API\Teams();
9+
$team->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
10+
```
11+
12+
### Get the team profile: (API 2.0)
13+
```php
14+
$team->profile($team_name);
15+
```
16+
17+
### Get the team members: (API 2.0)
18+
```php
19+
$team->members($team_name);
20+
```
21+
22+
### Get the team followers: (API 2.0)
23+
```php
24+
$team->followers($team_name);
25+
```
26+
27+
### Get a list of accounts the team is following: (API 2.0)
28+
```php
29+
$team->following($team_name);
30+
```
31+
32+
### Get the team's repositories: (API 2.0)
33+
```php
34+
$team->repositories($team_name);
35+
```
36+
37+
38+
----
39+
40+
#### Related:
41+
* [Authentication](authentication.md)
42+
* [BB Wiki](https://confluence.atlassian.com/x/XwZAGQ)

lib/Bitbucket/API/Teams.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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;
13+
14+
use Buzz\Message\MessageInterface;
15+
16+
/**
17+
* @author Alexandru G. <alex@gentle.ro>
18+
*/
19+
class Teams extends Api
20+
{
21+
/**
22+
* Get the public information associated with a team.
23+
*
24+
* @access public
25+
* @param string $name The team's name.
26+
* @return MessageInterface
27+
*/
28+
public function profile($name)
29+
{
30+
return $this->getClient()->setApiVersion('2.0')->get(
31+
sprintf('teams/%s', $name)
32+
);
33+
}
34+
35+
/**
36+
* Get the team members.
37+
*
38+
* @access public
39+
* @param string $name The team's name.
40+
* @return MessageInterface
41+
*/
42+
public function members($name)
43+
{
44+
return $this->getClient()->setApiVersion('2.0')->get(
45+
sprintf('teams/%s/members', $name)
46+
);
47+
}
48+
49+
/**
50+
* Get the team followers list.
51+
*
52+
* @access public
53+
* @param string $name The team's name.
54+
* @return MessageInterface
55+
*/
56+
public function followers($name)
57+
{
58+
return $this->getClient()->setApiVersion('2.0')->get(
59+
sprintf('teams/%s/followers', $name)
60+
);
61+
}
62+
63+
/**
64+
* Get a list of accounts the team is following.
65+
*
66+
* @access public
67+
* @param string $name The team's name.
68+
* @return MessageInterface
69+
*/
70+
public function following($name)
71+
{
72+
return $this->getClient()->setApiVersion('2.0')->get(
73+
sprintf('teams/%s/following', $name)
74+
);
75+
}
76+
77+
/**
78+
* Get the team's repositories.
79+
*
80+
* @access public
81+
* @param string $name The team's name.
82+
* @return MessageInterface
83+
*/
84+
public function repositories($name)
85+
{
86+
return $this->getClient()->setApiVersion('2.0')->get(
87+
sprintf('teams/%s/repositories', $name)
88+
);
89+
}
90+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
3+
namespace Bitbucket\Tests\API;
4+
5+
use Bitbucket\Tests\API as Tests;
6+
7+
class TeamsTest extends Tests\TestCase
8+
{
9+
public function testGetTeamProfile()
10+
{
11+
$endpoint = 'teams/gentle-web';
12+
$expectedResult = $this->fakeResponse(array('dummy'));
13+
14+
$client = $this->getHttpClientMock();
15+
$client->expects($this->once())
16+
->method('get')
17+
->with($endpoint)
18+
->will($this->returnValue($expectedResult));
19+
20+
/** @var \Bitbucket\API\Teams $team */
21+
$team = $this->getClassMock('Bitbucket\API\Teams', $client);
22+
$actual = $team->profile('gentle-web');
23+
24+
$this->assertEquals($expectedResult, $actual);
25+
}
26+
27+
public function testGetTeamMembers()
28+
{
29+
$endpoint = 'teams/gentle-web/members';
30+
$expectedResult = $this->fakeResponse(array('dummy'));
31+
32+
$client = $this->getHttpClientMock();
33+
$client->expects($this->once())
34+
->method('get')
35+
->with($endpoint)
36+
->will($this->returnValue($expectedResult));
37+
38+
/** @var \Bitbucket\API\Teams $team */
39+
$team = $this->getClassMock('Bitbucket\API\Teams', $client);
40+
$actual = $team->members('gentle-web');
41+
42+
$this->assertEquals($expectedResult, $actual);
43+
}
44+
45+
public function testGetTeamFollowers()
46+
{
47+
$endpoint = 'teams/gentle-web/followers';
48+
$expectedResult = $this->fakeResponse(array('dummy'));
49+
50+
$client = $this->getHttpClientMock();
51+
$client->expects($this->once())
52+
->method('get')
53+
->with($endpoint)
54+
->will($this->returnValue($expectedResult));
55+
56+
/** @var \Bitbucket\API\Teams $team */
57+
$team = $this->getClassMock('Bitbucket\API\Teams', $client);
58+
$actual = $team->followers('gentle-web');
59+
60+
$this->assertEquals($expectedResult, $actual);
61+
}
62+
63+
public function testGetTeamFollowing()
64+
{
65+
$endpoint = 'teams/gentle-web/following';
66+
$expectedResult = $this->fakeResponse(array('dummy'));
67+
68+
$client = $this->getHttpClientMock();
69+
$client->expects($this->once())
70+
->method('get')
71+
->with($endpoint)
72+
->will($this->returnValue($expectedResult));
73+
74+
/** @var \Bitbucket\API\Teams $team */
75+
$team = $this->getClassMock('Bitbucket\API\Teams', $client);
76+
$actual = $team->following('gentle-web');
77+
78+
$this->assertEquals($expectedResult, $actual);
79+
}
80+
81+
public function testGetTeamRepositories()
82+
{
83+
$endpoint = 'teams/gentle-web/repositories';
84+
$expectedResult = $this->fakeResponse(array('dummy'));
85+
86+
$client = $this->getHttpClientMock();
87+
$client->expects($this->once())
88+
->method('get')
89+
->with($endpoint)
90+
->will($this->returnValue($expectedResult));
91+
92+
/** @var \Bitbucket\API\Teams $team */
93+
$team = $this->getClassMock('Bitbucket\API\Teams', $client);
94+
$actual = $team->repositories('gentle-web');
95+
96+
$this->assertEquals($expectedResult, $actual);
97+
}
98+
}

0 commit comments

Comments
 (0)