Skip to content

Commit 142e85d

Browse files
author
Matt Humphrey
committed
Snippets tests and tidying up group tests
1 parent 3410dbe commit 142e85d

File tree

3 files changed

+136
-5
lines changed

3 files changed

+136
-5
lines changed

lib/Gitlab/Api/Snippets.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@ public function show($project_id, $snippet_id)
2626
* @param string $title
2727
* @param string $filename
2828
* @param string $code
29-
* @param string $lifetime
3029
* @return mixed
3130
*/
32-
public function create($project_id, $title, $filename, $code, $lifetime = null)
31+
public function create($project_id, $title, $filename, $code)
3332
{
3433
return $this->post($this->getProjectPath($project_id, 'snippets'), array(
3534
'title' => $title,
3635
'file_name' => $filename,
37-
'code' => $code,
38-
'lifetime' => $lifetime
36+
'code' => $code
3937
));
4038
}
4139

test/Gitlab/Tests/Api/GroupsTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class GroupsTest extends TestCase
77
/**
88
* @test
99
*/
10-
public function shouldGetAllProjects()
10+
public function shouldGetAllGroups()
1111
{
1212
$expectedArray = array(
1313
array('id' => 1, 'name' => 'A group'),
@@ -183,6 +183,23 @@ public function shouldRemoveMember()
183183
$this->assertEquals($expectedBool, $api->removeMember(1, 2));
184184
}
185185

186+
/**
187+
* @test
188+
*/
189+
public function shouldRemoveGroup()
190+
{
191+
$expectedBool = true;
192+
193+
$api = $this->getApiMock();
194+
$api->expects($this->once())
195+
->method('delete')
196+
->with('groups/1')
197+
->will($this->returnValue($expectedBool))
198+
;
199+
200+
$this->assertEquals($expectedBool, $api->remove(1));
201+
}
202+
186203
protected function getApiClass()
187204
{
188205
return 'Gitlab\Api\Groups';
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php namespace Gitlab\Tests\Api;
2+
3+
use Gitlab\Api\AbstractApi;
4+
5+
class SnippetsTest extends TestCase
6+
{
7+
/**
8+
* @test
9+
*/
10+
public function shouldGetAllSnippets()
11+
{
12+
$expectedArray = array(
13+
array('id' => 1, 'title' => 'A snippet'),
14+
array('id' => 2, 'title' => 'Another snippet'),
15+
);
16+
17+
$api = $this->getApiMock();
18+
$api->expects($this->once())
19+
->method('get')
20+
->with('projects/1/snippets')
21+
->will($this->returnValue($expectedArray))
22+
;
23+
24+
$this->assertEquals($expectedArray, $api->all(1));
25+
}
26+
27+
/**
28+
* @test
29+
*/
30+
public function shouldShowSnippet()
31+
{
32+
$expectedArray = array('id' => 2, 'title' => 'Another snippet');
33+
34+
$api = $this->getApiMock();
35+
$api->expects($this->once())
36+
->method('get')
37+
->with('projects/1/snippets/2')
38+
->will($this->returnValue($expectedArray))
39+
;
40+
41+
$this->assertEquals($expectedArray, $api->show(1, 2));
42+
}
43+
44+
/**
45+
* @test
46+
*/
47+
public function shouldCreateSnippet()
48+
{
49+
$expectedArray = array('id' => 3, 'title' => 'A new snippet');
50+
51+
$api = $this->getApiMock();
52+
$api->expects($this->once())
53+
->method('post')
54+
->with('projects/1/snippets', array('title' => 'A new snippet', 'code' => 'A file', 'file_name' => 'file.txt'))
55+
->will($this->returnValue($expectedArray))
56+
;
57+
58+
$this->assertEquals($expectedArray, $api->create(1, 'A new snippet', 'file.txt', 'A file'));
59+
}
60+
61+
/**
62+
* @test
63+
*/
64+
public function shouldUpdateSnippet()
65+
{
66+
$expectedArray = array('id' => 3, 'title' => 'Updated snippet');
67+
68+
$api = $this->getApiMock();
69+
$api->expects($this->once())
70+
->method('put')
71+
->with('projects/1/snippets/3', array('title' => 'Updated snippet', 'code' => 'New content', 'file_name' => 'new_file.txt'))
72+
->will($this->returnValue($expectedArray))
73+
;
74+
75+
$this->assertEquals($expectedArray, $api->update(1, 3, array('file_name' => 'new_file.txt', 'code' => 'New content', 'title' => 'Updated snippet')));
76+
}
77+
78+
/**
79+
* @test
80+
*/
81+
public function shouldShowContent()
82+
{
83+
$expectedString = 'New content';
84+
85+
$api = $this->getApiMock();
86+
$api->expects($this->once())
87+
->method('get')
88+
->with('projects/1/snippets/3/raw')
89+
->will($this->returnValue($expectedString))
90+
;
91+
92+
$this->assertEquals($expectedString, $api->content(1, 3));
93+
}
94+
95+
/**
96+
* @test
97+
*/
98+
public function shouldRemoveSnippet()
99+
{
100+
$expectedBool = true;
101+
102+
$api = $this->getApiMock();
103+
$api->expects($this->once())
104+
->method('delete')
105+
->with('projects/1/snippets/3')
106+
->will($this->returnValue($expectedBool))
107+
;
108+
109+
$this->assertEquals($expectedBool, $api->remove(1, 3));
110+
}
111+
112+
protected function getApiClass()
113+
{
114+
return 'Gitlab\Api\Snippets';
115+
}
116+
}

0 commit comments

Comments
 (0)