Skip to content

Commit 371215e

Browse files
Roman Dashevskym1guelpf
authored andcommitted
add get user's projects feature.
add unit test for it. change getMock to createMock in BuilderTest.php, getMock is deprecated method.
1 parent 52965f4 commit 371215e

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

lib/Gitlab/Api/Users.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ public function show($id)
6464
return $this->get('users/'.$this->encodePath($id));
6565
}
6666

67+
/**
68+
* @param int $id
69+
* @return mixed
70+
*/
71+
public function usersProjects($id)
72+
{
73+
return $this->get('users/'.$this->encodePath($id).'/projects');
74+
}
75+
6776
/**
6877
* @return mixed
6978
*/

test/Gitlab/Tests/Api/UsersTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,26 @@ public function shouldShowUser()
9292
$this->assertEquals($expectedArray, $api->show(1));
9393
}
9494

95+
/**
96+
* @test
97+
*/
98+
public function shouldShowUsersProjects()
99+
{
100+
$expectedArray = array(
101+
array('id' => 1, 'name' => 'matt-project-1'),
102+
array('id' => 2, 'name' => 'matt-project-2')
103+
);
104+
105+
$api = $this->getApiMock();
106+
$api->expects($this->once())
107+
->method('get')
108+
->with('users/1/projects')
109+
->will($this->returnValue($expectedArray))
110+
;
111+
112+
$this->assertEquals($expectedArray, $api->usersProjects(1));
113+
}
114+
95115
/**
96116
* @test
97117
*/

test/Gitlab/Tests/HttpClient/BuilderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,24 @@ class BuilderTest extends \PHPUnit_Framework_TestCase
2222
public function setUp()
2323
{
2424
$this->subject = new Builder(
25-
$this->getMock(HttpClient::class),
26-
$this->getMock(RequestFactory::class),
27-
$this->getMock(StreamFactory::class)
25+
$this->createMock(HttpClient::class),
26+
$this->createMock(RequestFactory::class),
27+
$this->createMock(StreamFactory::class)
2828
);
2929
}
3030

3131
public function testAddPluginShouldInvalidateHttpClient()
3232
{
3333
$client = $this->subject->getHttpClient();
3434

35-
$this->subject->addPlugin($this->getMock(Plugin::class));
35+
$this->subject->addPlugin($this->createMock(Plugin::class));
3636

3737
$this->assertNotSame($client, $this->subject->getHttpClient());
3838
}
3939

4040
public function testRemovePluginShouldInvalidateHttpClient()
4141
{
42-
$this->subject->addPlugin($this->getMock(Plugin::class));
42+
$this->subject->addPlugin($this->createMock(Plugin::class));
4343

4444
$client = $this->subject->getHttpClient();
4545

0 commit comments

Comments
 (0)