@@ -22,31 +22,43 @@ class DeploymentsTest extends TestCase
2222 * @test
2323 */
2424 public function shouldGetAllDeployments (): void
25+ {
26+ $ expectedArray = $ this ->getMultipleDeploymentsData ();
27+
28+ $ api = $ this ->getMultipleDeploymentsRequestMock ('projects/1/deployments ' , $ expectedArray , []);
29+
30+ $ this ->assertEquals ($ expectedArray , $ api ->all (1 ));
31+ }
32+
33+ /**
34+ * @test
35+ */
36+ public function shouldShowDeployment (): void
2537 {
2638 $ expectedArray = [
2739 [
28- 'created_at ' => '2016-08-11T07:36:40.222Z ' ,
40+ 'created_at ' => '2016-08-11T11:32:35.444Z ' ,
2941 'deployable ' => [
3042 'commit ' => [
3143 'author_email ' => 'admin@example.com ' ,
3244 'author_name ' => 'Administrator ' ,
33- 'created_at ' => '2016-08-11T09:36:01 .000+02:00 ' ,
34- 'id ' => '99d03678b90d914dbb1b109132516d71a4a03ea8 ' ,
35- 'message ' => 'Merge branch \'new-title \' into \'master \'
45+ 'created_at ' => '2016-08-11T13:28:26 .000+02:00 ' ,
46+ 'id ' => 'a91957a858320c0e17f3a0eca7cfacbff50ea29a ' ,
47+ 'message ' => 'Merge branch \'rename-readme \' into \'master \'
3648
37- Update README
49+ Rename README
3850
3951
4052
41- See merge request !1 ' ,
42- 'short_id ' => '99d03678 ' ,
43- 'title ' => 'Merge branch \'new-title \' into \'master \'
53+ See merge request !2 ' ,
54+ 'short_id ' => 'a91957a8 ' ,
55+ 'title ' => 'Merge branch \'rename-readme \' into \'master \'
4456 ' ,
4557 ],
4658 'coverage ' => null ,
47- 'created_at ' => '2016-08-11T07:36:27.357Z ' ,
48- 'finished_at ' => '2016-08-11T07:36:39.851Z ' ,
49- 'id ' => 657 ,
59+ 'created_at ' => '2016-08-11T11:32:24.456Z ' ,
60+ 'finished_at ' => '2016-08-11T11:32:35.145Z ' ,
61+ 'id ' => 664 ,
5062 'name ' => 'deploy ' ,
5163 'ref ' => 'master ' ,
5264 'runner ' => null ,
@@ -75,10 +87,10 @@ public function shouldGetAllDeployments(): void
7587 'id ' => 9 ,
7688 'name ' => 'production ' ,
7789 ],
78- 'id ' => 41 ,
79- 'iid ' => 1 ,
90+ 'id ' => 42 ,
91+ 'iid ' => 2 ,
8092 'ref ' => 'master ' ,
81- 'sha ' => '99d03678b90d914dbb1b109132516d71a4a03ea8 ' ,
93+ 'sha ' => 'a91957a858320c0e17f3a0eca7cfacbff50ea29a ' ,
8294 'user ' => [
8395 'avatar_url ' => 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon ' ,
8496 'id ' => 1 ,
@@ -88,29 +100,42 @@ public function shouldGetAllDeployments(): void
88100 'web_url ' => 'http://localhost:3000/root ' ,
89101 ],
90102 ],
103+ ];
104+
105+ $ api = $ this ->getApiMock ();
106+ $ api ->expects ($ this ->once ())
107+ ->method ('get ' )
108+ ->with ('projects/1/deployments/42 ' )
109+ ->will ($ this ->returnValue ($ expectedArray ));
110+ $ this ->assertEquals ($ expectedArray , $ api ->show (1 , 42 ));
111+ }
112+
113+ private function getMultipleDeploymentsData ()
114+ {
115+ return [
91116 [
92- 'created_at ' => '2016-08-11T11:32:35.444Z ' ,
117+ 'created_at ' => '2016-08-11T07:36:40.222Z ' ,
93118 'deployable ' => [
94119 'commit ' => [
95120 'author_email ' => 'admin@example.com ' ,
96121 'author_name ' => 'Administrator ' ,
97- 'created_at ' => '2016-08-11T13:28:26 .000+02:00 ' ,
98- 'id ' => 'a91957a858320c0e17f3a0eca7cfacbff50ea29a ' ,
99- 'message ' => 'Merge branch \'rename-readme \' into \'master \'
122+ 'created_at ' => '2016-08-11T09:36:01 .000+02:00 ' ,
123+ 'id ' => '99d03678b90d914dbb1b109132516d71a4a03ea8 ' ,
124+ 'message ' => 'Merge branch \'new-title \' into \'master \'
100125
101- Rename README
126+ Update README
102127
103128
104129
105- See merge request !2 ' ,
106- 'short_id ' => 'a91957a8 ' ,
107- 'title ' => 'Merge branch \'rename-readme \' into \'master \'
130+ See merge request !1 ' ,
131+ 'short_id ' => '99d03678 ' ,
132+ 'title ' => 'Merge branch \'new-title \' into \'master \'
108133 ' ,
109134 ],
110135 'coverage ' => null ,
111- 'created_at ' => '2016-08-11T11:32:24.456Z ' ,
112- 'finished_at ' => '2016-08-11T11:32:35.145Z ' ,
113- 'id ' => 664 ,
136+ 'created_at ' => '2016-08-11T07:36:27.357Z ' ,
137+ 'finished_at ' => '2016-08-11T07:36:39.851Z ' ,
138+ 'id ' => 657 ,
114139 'name ' => 'deploy ' ,
115140 'ref ' => 'master ' ,
116141 'runner ' => null ,
@@ -139,10 +164,10 @@ public function shouldGetAllDeployments(): void
139164 'id ' => 9 ,
140165 'name ' => 'production ' ,
141166 ],
142- 'id ' => 42 ,
143- 'iid ' => 2 ,
167+ 'id ' => 41 ,
168+ 'iid ' => 1 ,
144169 'ref ' => 'master ' ,
145- 'sha ' => 'a91957a858320c0e17f3a0eca7cfacbff50ea29a ' ,
170+ 'sha ' => '99d03678b90d914dbb1b109132516d71a4a03ea8 ' ,
146171 'user ' => [
147172 'avatar_url ' => 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon ' ,
148173 'id ' => 1 ,
@@ -152,22 +177,6 @@ public function shouldGetAllDeployments(): void
152177 'web_url ' => 'http://localhost:3000/root ' ,
153178 ],
154179 ],
155- ];
156-
157- $ api = $ this ->getApiMock ();
158- $ api ->expects ($ this ->once ())
159- ->method ('get ' )
160- ->with ('projects/1/deployments ' )
161- ->will ($ this ->returnValue ($ expectedArray ));
162- $ this ->assertEquals ($ expectedArray , $ api ->all (1 ));
163- }
164-
165- /**
166- * @test
167- */
168- public function shouldShowDeployment (): void
169- {
170- $ expectedArray = [
171180 [
172181 'created_at ' => '2016-08-11T11:32:35.444Z ' ,
173182 'deployable ' => [
@@ -233,13 +242,36 @@ public function shouldShowDeployment(): void
233242 ],
234243 ],
235244 ];
245+ }
236246
247+ protected function getMultipleDeploymentsRequestMock (string $ path , array $ expectedArray , array $ expectedParameters )
248+ {
237249 $ api = $ this ->getApiMock ();
238250 $ api ->expects ($ this ->once ())
239251 ->method ('get ' )
240- ->with (' projects/1/deployments/42 ' )
252+ ->with ($ path , $ expectedParameters )
241253 ->will ($ this ->returnValue ($ expectedArray ));
242- $ this ->assertEquals ($ expectedArray , $ api ->show (1 , 42 ));
254+
255+ return $ api ;
256+ }
257+
258+ /**
259+ * @test
260+ */
261+ public function shouldGetAllDeploymentsSortedByCreatedAt (): void
262+ {
263+ $ expectedArray = $ this ->getMultipleDeploymentsData ();
264+
265+ $ api = $ this ->getMultipleDeploymentsRequestMock (
266+ 'projects/1/deployments ' ,
267+ $ expectedArray ,
268+ ['page ' => 1 , 'per_page ' => 5 , 'order_by ' => 'created_at ' , 'sort ' => 'asc ' ]
269+ );
270+
271+ $ this ->assertEquals (
272+ $ expectedArray ,
273+ $ api ->all (1 , ['page ' => 1 , 'per_page ' => 5 , 'order_by ' => 'created_at ' , 'sort ' => 'asc ' ])
274+ );
243275 }
244276
245277 protected function getApiClass ()
0 commit comments