Skip to content

Commit 2da864d

Browse files
author
Matt Humphrey
committed
Milestone tests
1 parent d857d42 commit 2da864d

File tree

2 files changed

+105
-5
lines changed

2 files changed

+105
-5
lines changed

lib/Gitlab/Api/Milestones.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Milestones extends AbstractApi
1010
*/
1111
public function all($project_id, $page = 1, $per_page = self::PER_PAGE)
1212
{
13-
return $this->get($this->getProjectPath($project_id, '/milestones'), array(
13+
return $this->get($this->getProjectPath($project_id, 'milestones'), array(
1414
'page' => $page,
1515
'per_page' => $per_page
1616
));
@@ -23,7 +23,7 @@ public function all($project_id, $page = 1, $per_page = self::PER_PAGE)
2323
*/
2424
public function show($project_id, $milestone_id)
2525
{
26-
return $this->get($this->getProjectPath($project_id, '/milestones/'.urlencode($milestone_id)));
26+
return $this->get($this->getProjectPath($project_id, 'milestones/'.urlencode($milestone_id)));
2727
}
2828

2929
/**
@@ -33,7 +33,7 @@ public function show($project_id, $milestone_id)
3333
*/
3434
public function create($project_id, array $params)
3535
{
36-
return $this->post($this->getProjectPath($project_id, '/milestones'), $params);
36+
return $this->post($this->getProjectPath($project_id, 'milestones'), $params);
3737
}
3838

3939
/**
@@ -44,7 +44,7 @@ public function create($project_id, array $params)
4444
*/
4545
public function update($project_id, $milestone_id, array $params)
4646
{
47-
return $this->put($this->getProjectPath($project_id, '/milestones/'.urlencode($milestone_id)), $params);
47+
return $this->put($this->getProjectPath($project_id, 'milestones/'.urlencode($milestone_id)), $params);
4848
}
4949

5050
/**
@@ -54,6 +54,6 @@ public function update($project_id, $milestone_id, array $params)
5454
*/
5555
public function issues($project_id, $milestone_id)
5656
{
57-
return $this->get($this->getProjectPath($project_id, '/milestones/'.urlencode($milestone_id).'/issues'));
57+
return $this->get($this->getProjectPath($project_id, 'milestones/'.urlencode($milestone_id).'/issues'));
5858
}
5959
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php namespace Gitlab\Tests\Api;
2+
3+
class MilestonesTest extends TestCase
4+
{
5+
/**
6+
* @test
7+
*/
8+
public function shouldGetAllMilestones()
9+
{
10+
$expectedArray = array(
11+
array('id' => 1, 'title' => 'A milestone'),
12+
array('id' => 2, 'title' => 'Another milestone'),
13+
);
14+
15+
$api = $this->getApiMock();
16+
$api->expects($this->once())
17+
->method('get')
18+
->with('projects/1/milestones')
19+
->will($this->returnValue($expectedArray))
20+
;
21+
22+
$this->assertEquals($expectedArray, $api->all(1));
23+
}
24+
25+
/**
26+
* @test
27+
*/
28+
public function shouldShowMilestone()
29+
{
30+
$expectedArray = array('id' => 1, 'name' => 'A milestone');
31+
32+
$api = $this->getApiMock();
33+
$api->expects($this->once())
34+
->method('get')
35+
->with('projects/1/milestones/2')
36+
->will($this->returnValue($expectedArray))
37+
;
38+
39+
$this->assertEquals($expectedArray, $api->show(1, 2));
40+
}
41+
42+
/**
43+
* @test
44+
*/
45+
public function shouldCreateMilestone()
46+
{
47+
$expectedArray = array('id' => 3, 'title' => 'A new milestone');
48+
49+
$api = $this->getApiMock();
50+
$api->expects($this->once())
51+
->method('post')
52+
->with('projects/1/milestones', array('description' => 'Some text', 'title' => 'A new milestone'))
53+
->will($this->returnValue($expectedArray))
54+
;
55+
56+
$this->assertEquals($expectedArray, $api->create(1, array('description' => 'Some text', 'title' => 'A new milestone')));
57+
}
58+
59+
/**
60+
* @test
61+
*/
62+
public function shouldUpdateMilestone()
63+
{
64+
$expectedArray = array('id' => 3, 'title' => 'Updated milestone');
65+
66+
$api = $this->getApiMock();
67+
$api->expects($this->once())
68+
->method('put')
69+
->with('projects/1/milestones/3', array('title' => 'Updated milestone', 'due_date' => '2015-04-01', 'state_event' => 'close'))
70+
->will($this->returnValue($expectedArray))
71+
;
72+
73+
$this->assertEquals($expectedArray, $api->update(1, 3, array('title' => 'Updated milestone', 'due_date' => '2015-04-01', 'state_event' => 'close')));
74+
}
75+
76+
/**
77+
* @test
78+
*/
79+
public function shouldGetMilestonesIssues()
80+
{
81+
$expectedArray = array(
82+
array('id' => 1, 'title' => 'An issue'),
83+
array('id' => 2, 'title' => 'Another issue'),
84+
);
85+
86+
$api = $this->getApiMock();
87+
$api->expects($this->once())
88+
->method('get')
89+
->with('projects/1/milestones/3/issues')
90+
->will($this->returnValue($expectedArray))
91+
;
92+
93+
$this->assertEquals($expectedArray, $api->issues(1, 3));
94+
}
95+
96+
protected function getApiClass()
97+
{
98+
return 'Gitlab\Api\Milestones';
99+
}
100+
}

0 commit comments

Comments
 (0)