1
|
|
|
<?php |
2
|
|
|
namespace spec\DevBoardLib\GithubObjectApiFacade\Repo\Milestone\Converter; |
3
|
|
|
|
4
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepo; |
5
|
|
|
use DevBoardLib\GithubCore\Repo\GithubRepoId; |
6
|
|
|
use PhpSpec\ObjectBehavior; |
7
|
|
|
use Prophecy\Argument; |
8
|
|
|
use tests\DevBoardLib\GithubObjectApiFacade\SampleDataProvider; |
9
|
|
|
|
10
|
|
|
class GithubMilestoneConverterSpec extends ObjectBehavior |
11
|
|
|
{ |
12
|
|
|
public function it_is_initializable() |
13
|
|
|
{ |
14
|
|
|
$this->shouldHaveType('DevBoardLib\GithubObjectApiFacade\Repo\Milestone\Converter\GithubMilestoneConverter'); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function let(GithubRepo $githubRepo, GithubRepoId $repoId) |
18
|
|
|
{ |
19
|
|
|
$githubRepo->getId()->willReturn($repoId); |
20
|
|
|
$this->beConstructedWith($githubRepo); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @dataProvider provideAllMilestones |
25
|
|
|
*/ |
26
|
|
|
public function it_returns_github_milestone_source_as_result($arrayData) |
27
|
|
|
{ |
28
|
|
|
$this->convert($arrayData) |
29
|
|
|
->shouldReturnAnInstanceOf('DevBoardLib\GithubCore\Milestone\GithubMilestoneSource'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @dataProvider provideAllMilestones |
34
|
|
|
*/ |
35
|
|
|
public function it_will_have_milestone_id_in_converted_result($arrayData) |
36
|
|
|
{ |
37
|
|
|
$result = $this->convert($arrayData); |
38
|
|
|
|
39
|
|
|
$result->getId()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Milestone\GithubMilestoneId'); |
40
|
|
|
$result->getId()->__toString()->shouldBe((string) $arrayData['id']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @dataProvider provideAllMilestones |
45
|
|
|
*/ |
46
|
|
|
public function it_will_have_repo_id_in_converted_result($arrayData) |
47
|
|
|
{ |
48
|
|
|
$result = $this->convert($arrayData); |
49
|
|
|
|
50
|
|
|
//@TODO: How to test repo & id? (injecting does not work :( ) |
51
|
|
|
$result->getRepoId()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Repo\GithubRepoId'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @dataProvider provideAllMilestones |
56
|
|
|
*/ |
57
|
|
|
public function it_will_have_repo_in_converted_result($arrayData) |
58
|
|
|
{ |
59
|
|
|
$result = $this->convert($arrayData); |
60
|
|
|
|
61
|
|
|
//@TODO: How to test repo & id? (injecting does not work :( ) |
62
|
|
|
$result->getRepo()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Repo\GithubRepo'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @dataProvider provideAllMilestones |
67
|
|
|
*/ |
68
|
|
|
public function it_will_have_milestone_number_in_converted_result($arrayData) |
69
|
|
|
{ |
70
|
|
|
$result = $this->convert($arrayData); |
71
|
|
|
$result->getNumber()->shouldBe($arrayData['number']); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @dataProvider provideAllMilestones |
76
|
|
|
*/ |
77
|
|
|
public function it_will_have_milestone_state_in_converted_result($arrayData) |
78
|
|
|
{ |
79
|
|
|
$result = $this->convert($arrayData); |
80
|
|
|
$result->getState()->__toString()->shouldBe((string) $arrayData['state']); |
81
|
|
|
$result->getState()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Milestone\State\GithubMilestoneState'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @dataProvider provideOpenMilestones |
86
|
|
|
*/ |
87
|
|
|
public function it_will_have_open_milestone_state_in_converted_result($arrayData) |
88
|
|
|
{ |
89
|
|
|
$result = $this->convert($arrayData); |
90
|
|
|
$result->getState()->__toString()->shouldBe('open'); |
91
|
|
|
$result->getState()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Milestone\State\GithubMilestoneOpenState'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @dataProvider provideClosedMilestones |
96
|
|
|
*/ |
97
|
|
|
public function it_will_have_closed_milestone_state_in_converted_result($arrayData) |
98
|
|
|
{ |
99
|
|
|
$result = $this->convert($arrayData); |
100
|
|
|
$result->getState()->__toString()->shouldBe('closed'); |
101
|
|
|
$result->getState()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Milestone\State\GithubMilestoneClosedState'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @dataProvider provideAllMilestones |
106
|
|
|
*/ |
107
|
|
|
public function it_will_have_milestone_title_in_converted_result($arrayData) |
108
|
|
|
{ |
109
|
|
|
$result = $this->convert($arrayData); |
110
|
|
|
$result->getTitle()->shouldBe((string) $arrayData['title']); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @dataProvider provideAllMilestones |
115
|
|
|
*/ |
116
|
|
|
public function it_will_have_milestone_description_in_converted_result($arrayData) |
117
|
|
|
{ |
118
|
|
|
$result = $this->convert($arrayData); |
119
|
|
|
$result->getDescription()->shouldBe((string) $arrayData['description']); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @dataProvider provideMilestonesWithCreator |
124
|
|
|
*/ |
125
|
|
|
public function it_will_have_user_id_of_creator_in_converted_result($arrayData) |
126
|
|
|
{ |
127
|
|
|
$result = $this->convert($arrayData); |
128
|
|
|
|
129
|
|
|
$result->getCreatedByUserId() |
130
|
|
|
->shouldBeAnInstanceOf('DevBoardLib\GithubCore\User\GithubUserId'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @dataProvider provideMilestonesWithCreator |
135
|
|
|
*/ |
136
|
|
|
public function it_will_have_creator_in_converted_result($arrayData) |
137
|
|
|
{ |
138
|
|
|
$result = $this->convert($arrayData); |
139
|
|
|
|
140
|
|
|
$result->getCreatedByUser() |
141
|
|
|
->shouldBeAnInstanceOf('DevBoardLib\GithubCore\User\GithubUserSource'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @dataProvider provideMilestonesWithOutCreator |
146
|
|
|
*/ |
147
|
|
|
public function it_will_have_null_for_user_id_of_creator_in_converted_result($arrayData) |
148
|
|
|
{ |
149
|
|
|
$result = $this->convert($arrayData); |
150
|
|
|
|
151
|
|
|
$result->getCreatedByUserId()->shouldReturn(null); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @dataProvider provideMilestonesWithOutCreator |
156
|
|
|
*/ |
157
|
|
|
public function it_will_have_null_for_creator_in_converted_result($arrayData) |
158
|
|
|
{ |
159
|
|
|
$result = $this->convert($arrayData); |
160
|
|
|
|
161
|
|
|
$result->getCreatedByUser()->shouldReturn(null); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @dataProvider provideAllMilestones |
166
|
|
|
*/ |
167
|
|
|
public function it_will_have_open_issue_count_in_converted_result($arrayData) |
168
|
|
|
{ |
169
|
|
|
$result = $this->convert($arrayData); |
170
|
|
|
$result->getOpenIssueCount()->shouldBe($arrayData['open_issues']); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @dataProvider provideAllMilestones |
175
|
|
|
*/ |
176
|
|
|
public function it_will_have_closed_issue_count_in_converted_result($arrayData) |
177
|
|
|
{ |
178
|
|
|
$result = $this->convert($arrayData); |
179
|
|
|
$result->getClosedIssueCount()->shouldBe($arrayData['closed_issues']); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @dataProvider provideMilestonesWithDueDate |
184
|
|
|
*/ |
185
|
|
|
public function it_will_have_due_date_in_converted_result($arrayData) |
186
|
|
|
{ |
187
|
|
|
$result = $this->convert($arrayData); |
188
|
|
|
|
189
|
|
|
if (null !== $arrayData['due_on']) { |
190
|
|
|
$result->getDueDate()->shouldBeAnInstanceOf('DateTime'); |
191
|
|
|
$result->getDueDate()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['due_on']); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @dataProvider provideMilestonesWithOutDueDate |
197
|
|
|
*/ |
198
|
|
|
public function it_will_have_null_if_no_due_date_in_converted_result($arrayData) |
199
|
|
|
{ |
200
|
|
|
$result = $this->convert($arrayData); |
201
|
|
|
|
202
|
|
|
if (null === $arrayData['due_on']) { |
203
|
|
|
$result->getDueDate()->shouldBe(null); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @dataProvider provideAllMilestones |
209
|
|
|
*/ |
210
|
|
View Code Duplication |
public function it_will_have_github_created_datetime_in_converted_result($arrayData) |
|
|
|
|
211
|
|
|
{ |
212
|
|
|
$result = $this->convert($arrayData); |
213
|
|
|
|
214
|
|
|
$result->getGithubCreatedAt()->shouldBeAnInstanceOf('DateTime'); |
215
|
|
|
$result->getGithubCreatedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['created_at']); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @dataProvider provideAllMilestones |
220
|
|
|
*/ |
221
|
|
View Code Duplication |
public function it_will_have_github_last_updated_datetime_in_converted_result($arrayData) |
|
|
|
|
222
|
|
|
{ |
223
|
|
|
$result = $this->convert($arrayData); |
224
|
|
|
|
225
|
|
|
$result->getGithubUpdatedAt()->shouldBeAnInstanceOf('DateTime'); |
226
|
|
|
$result->getGithubUpdatedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['updated_at']); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @dataProvider provideClosedMilestones |
231
|
|
|
*/ |
232
|
|
View Code Duplication |
public function it_will_have_github_closed_datetime_for_closed_milestones_in_converted_result($arrayData) |
|
|
|
|
233
|
|
|
{ |
234
|
|
|
$result = $this->convert($arrayData); |
235
|
|
|
|
236
|
|
|
$result->getGithubClosedAt()->shouldBeAnInstanceOf('DateTime'); |
237
|
|
|
$result->getGithubClosedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['closed_at']); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @dataProvider provideOpenMilestones |
242
|
|
|
*/ |
243
|
|
|
public function it_will_have_null_for_github_closed_datetime_on_open_milestones_in_converted_result($arrayData) |
244
|
|
|
{ |
245
|
|
|
$result = $this->convert($arrayData); |
246
|
|
|
|
247
|
|
|
$result->getGithubClosedAt()->shouldBe(null); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function provideAllMilestones() |
251
|
|
|
{ |
252
|
|
|
$testData = []; |
253
|
|
|
|
254
|
|
|
foreach ($this->getDataProvider()->getAllMilestones() as $item) { |
255
|
|
|
$testData[] = [$item]; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
return $testData; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
public function provideOpenMilestones() |
262
|
|
|
{ |
263
|
|
|
$testData = []; |
264
|
|
|
|
265
|
|
|
foreach ($this->getDataProvider()->getAllMilestones() as $item) { |
266
|
|
|
if ('open' === $item['state']) { |
267
|
|
|
$testData[] = [$item]; |
268
|
|
|
} |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
return $testData; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
public function provideClosedMilestones() |
275
|
|
|
{ |
276
|
|
|
$testData = []; |
277
|
|
|
|
278
|
|
|
foreach ($this->getDataProvider()->getAllMilestones() as $item) { |
279
|
|
|
if ('closed' === $item['state']) { |
280
|
|
|
$testData[] = [$item]; |
281
|
|
|
} |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
return $testData; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
public function provideMilestonesWithDueDate() |
288
|
|
|
{ |
289
|
|
|
$testData = []; |
290
|
|
|
|
291
|
|
|
foreach ($this->getDataProvider()->getAllMilestones() as $item) { |
292
|
|
|
if (null !== $item['due_on']) { |
293
|
|
|
$testData[] = [$item]; |
294
|
|
|
} |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
return $testData; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
public function provideMilestonesWithOutDueDate() |
301
|
|
|
{ |
302
|
|
|
$testData = []; |
303
|
|
|
|
304
|
|
|
foreach ($this->getDataProvider()->getAllMilestones() as $item) { |
305
|
|
|
if (null === $item['due_on']) { |
306
|
|
|
$testData[] = [$item]; |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
return $testData; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
public function provideMilestonesWithCreator() |
314
|
|
|
{ |
315
|
|
|
$testData = []; |
316
|
|
|
|
317
|
|
|
foreach ($this->getDataProvider()->getAllMilestones() as $item) { |
318
|
|
|
if (null !== $item['creator']) { |
319
|
|
|
$testData[] = [$item]; |
320
|
|
|
} |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
return $testData; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
public function provideMilestonesWithOutCreator() |
327
|
|
|
{ |
328
|
|
|
$testData = []; |
329
|
|
|
|
330
|
|
|
foreach ($this->getDataProvider()->getAllMilestones() as $item) { |
331
|
|
|
if (null === $item['creator']) { |
332
|
|
|
$testData[] = [$item]; |
333
|
|
|
} |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
return $testData; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
protected function getDataProvider() |
340
|
|
|
{ |
341
|
|
|
return new SampleDataProvider(); |
342
|
|
|
} |
343
|
|
|
} |
344
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.