@@ -22,31 +22,43 @@ class DeploymentsTest extends TestCase
22
22
* @test
23
23
*/
24
24
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
25
37
{
26
38
$ expectedArray = [
27
39
[
28
- 'created_at ' => '2016-08-11T07:36:40.222Z ' ,
40
+ 'created_at ' => '2016-08-11T11:32:35.444Z ' ,
29
41
'deployable ' => [
30
42
'commit ' => [
31
43
'author_email ' =>
'[email protected] ' ,
32
44
'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 \'
36
48
37
- Update README
49
+ Rename README
38
50
39
51
40
52
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 \'
44
56
' ,
45
57
],
46
58
'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 ,
50
62
'name ' => 'deploy ' ,
51
63
'ref ' => 'master ' ,
52
64
'runner ' => null ,
@@ -75,10 +87,10 @@ public function shouldGetAllDeployments(): void
75
87
'id ' => 9 ,
76
88
'name ' => 'production ' ,
77
89
],
78
- 'id ' => 41 ,
79
- 'iid ' => 1 ,
90
+ 'id ' => 42 ,
91
+ 'iid ' => 2 ,
80
92
'ref ' => 'master ' ,
81
- 'sha ' => '99d03678b90d914dbb1b109132516d71a4a03ea8 ' ,
93
+ 'sha ' => 'a91957a858320c0e17f3a0eca7cfacbff50ea29a ' ,
82
94
'user ' => [
83
95
'avatar_url ' => 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon ' ,
84
96
'id ' => 1 ,
@@ -88,29 +100,42 @@ public function shouldGetAllDeployments(): void
88
100
'web_url ' => 'http://localhost:3000/root ' ,
89
101
],
90
102
],
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 [
91
116
[
92
- 'created_at ' => '2016-08-11T11:32:35.444Z ' ,
117
+ 'created_at ' => '2016-08-11T07:36:40.222Z ' ,
93
118
'deployable ' => [
94
119
'commit ' => [
95
120
'author_email ' =>
'[email protected] ' ,
96
121
'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 \'
100
125
101
- Rename README
126
+ Update README
102
127
103
128
104
129
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 \'
108
133
' ,
109
134
],
110
135
'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 ,
114
139
'name ' => 'deploy ' ,
115
140
'ref ' => 'master ' ,
116
141
'runner ' => null ,
@@ -139,10 +164,10 @@ public function shouldGetAllDeployments(): void
139
164
'id ' => 9 ,
140
165
'name ' => 'production ' ,
141
166
],
142
- 'id ' => 42 ,
143
- 'iid ' => 2 ,
167
+ 'id ' => 41 ,
168
+ 'iid ' => 1 ,
144
169
'ref ' => 'master ' ,
145
- 'sha ' => 'a91957a858320c0e17f3a0eca7cfacbff50ea29a ' ,
170
+ 'sha ' => '99d03678b90d914dbb1b109132516d71a4a03ea8 ' ,
146
171
'user ' => [
147
172
'avatar_url ' => 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon ' ,
148
173
'id ' => 1 ,
@@ -152,22 +177,6 @@ public function shouldGetAllDeployments(): void
152
177
'web_url ' => 'http://localhost:3000/root ' ,
153
178
],
154
179
],
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 = [
171
180
[
172
181
'created_at ' => '2016-08-11T11:32:35.444Z ' ,
173
182
'deployable ' => [
@@ -233,13 +242,36 @@ public function shouldShowDeployment(): void
233
242
],
234
243
],
235
244
];
245
+ }
236
246
247
+ protected function getMultipleDeploymentsRequestMock (string $ path , array $ expectedArray , array $ expectedParameters )
248
+ {
237
249
$ api = $ this ->getApiMock ();
238
250
$ api ->expects ($ this ->once ())
239
251
->method ('get ' )
240
- ->with (' projects/1/deployments/42 ' )
252
+ ->with ($ path , $ expectedParameters )
241
253
->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
+ );
243
275
}
244
276
245
277
protected function getApiClass ()
0 commit comments