GithubIssueConverterSpec::provideAllIssues()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace spec\DevBoardLib\GithubObjectApiFacade\Repo\Issue\Converter;
4
5
use DevBoardLib\GithubCore\Repo\GithubRepo;
6
use DevBoardLib\GithubCore\Repo\GithubRepoId;
7
use PhpSpec\ObjectBehavior;
8
use Prophecy\Argument;
9
use tests\DevBoardLib\GithubObjectApiFacade\JsonSampleDataProvider;
10
11
class GithubIssueConverterSpec extends ObjectBehavior
12
{
13
    public function it_is_initializable()
14
    {
15
        $this->shouldHaveType('DevBoardLib\GithubObjectApiFacade\Repo\Issue\Converter\GithubIssueConverter');
16
    }
17
18
    public function let(GithubRepo $githubRepo, GithubRepoId $repoId)
19
    {
20
        $githubRepo->getId()->willReturn($repoId);
21
        $this->beConstructedWith($githubRepo);
22
    }
23
24
    /**
25
     * @dataProvider provideAllIssues
26
     */
27
    public function it_returns_github_issue_source_as_result($arrayData)
28
    {
29
        $this->convert($arrayData)
30
            ->shouldReturnAnInstanceOf('DevBoardLib\GithubCore\Issue\GithubIssueSource');
31
    }
32
33
    /**
34
     * @dataProvider provideAllIssues
35
     */
36
    public function it_will_have_repo_id_in_converted_result($arrayData)
37
    {
38
        $result = $this->convert($arrayData);
39
40
        //@TODO: How to test repo & id? (injecting does not work :( )
41
        $result->getRepoId()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Repo\GithubRepoId');
42
    }
43
44
    /**
45
     * @dataProvider provideAllIssues
46
     */
47
    public function it_will_have_repo_in_converted_result($arrayData)
48
    {
49
        $result = $this->convert($arrayData);
50
51
        //@TODO: How to test repo & id? (injecting does not work :( )
52
        $result->getRepo()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Repo\GithubRepo');
53
    }
54
55
    //
56
    //
57
    //
58
    //
59
60
    /**
61
     * @dataProvider provideAllIssues
62
     */
63
    public function it_will_have_issue_state_in_converted_result($arrayData)
64
    {
65
        $result = $this->convert($arrayData);
66
        $result->getState()->__toString()->shouldBe((string) $arrayData['state']);
67
        $result->getState()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Issue\State\GithubIssueState');
68
    }
69
70
    /**
71
     * @dataProvider provideOpenIssues
72
     */
73
    public function it_will_have_open_issue_state_in_converted_result($arrayData)
74
    {
75
        $result = $this->convert($arrayData);
76
        $result->getState()->__toString()->shouldBe('open');
77
        $result->getState()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Issue\State\GithubIssueOpenState');
78
    }
79
80
    /**
81
     * @dataProvider provideClosedIssues
82
     */
83
    public function it_will_have_closed_issue_state_in_converted_result($arrayData)
84
    {
85
        $result = $this->convert($arrayData);
86
        $result->getState()->__toString()->shouldBe('closed');
87
        $result->getState()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Issue\State\GithubIssueClosedState');
88
    }
89
90
    /**
91
     * @dataProvider provideAllIssues
92
     */
93
    public function it_will_have_issue_title_in_converted_result($arrayData)
94
    {
95
        $result = $this->convert($arrayData);
96
        $result->getTitle()->shouldBe((string) $arrayData['title']);
97
    }
98
99
    /**
100
     * @dataProvider provideAllIssues
101
     */
102
    public function it_will_have_issue_description_in_converted_result($arrayData)
103
    {
104
        $result = $this->convert($arrayData);
105
        $result->getBody()->shouldBe((string) $arrayData['body']);
106
    }
107
108
    /**
109
     * @dataProvider provideAllIssues
110
     */
111
    public function it_will_have_user_id_of_creator_in_converted_result($arrayData)
112
    {
113
        $result = $this->convert($arrayData);
114
115
        $result->getCreatedByUserId()
116
            ->shouldBeAnInstanceOf('DevBoardLib\GithubCore\User\GithubUserId');
117
    }
118
119
    /**
120
     * @dataProvider provideAllIssues
121
     */
122
    public function it_will_have_creator_in_converted_result($arrayData)
123
    {
124
        $result = $this->convert($arrayData);
125
126
        $result->getCreatedByUser()
127
            ->shouldBeAnInstanceOf('DevBoardLib\GithubCore\User\GithubUserSource');
128
    }
129
130
    /**
131
     * @dataProvider provideAssignedIssues
132
     */
133
    public function it_will_have_user_id_of_assigned_user_in_converted_result($arrayData)
134
    {
135
        $result = $this->convert($arrayData);
136
137
        $result->getAssignedToUserId()
138
            ->shouldBeAnInstanceOf('DevBoardLib\GithubCore\User\GithubUserId');
139
    }
140
141
    /**
142
     * @dataProvider provideAssignedIssues
143
     */
144
    public function it_will_have_assigned_user_in_converted_result($arrayData)
145
    {
146
        $result = $this->convert($arrayData);
147
148
        $result->getAssignedToUser()
149
            ->shouldBeAnInstanceOf('DevBoardLib\GithubCore\User\GithubUserSource');
150
    }
151
152
    /**
153
     * @dataProvider provideNonAssignedIssues
154
     */
155
    public function it_will_have_null_for_user_id_on_unassigned_user_in_converted_result($arrayData)
156
    {
157
        $result = $this->convert($arrayData);
158
159
        $result->getAssignedToUserId()->shouldBe(null);
160
    }
161
162
    /**
163
     * @dataProvider provideNonAssignedIssues
164
     */
165
    public function it_will_have_null_for_user_on_unassigned_user_in_converted_result($arrayData)
166
    {
167
        $result = $this->convert($arrayData);
168
169
        $result->getAssignedToUser()->shouldBe(null);
170
    }
171
172
    /**
173
     * @dataProvider provideMilestonedIssues
174
     */
175
    public function it_will_have_milestone_in_converted_result($arrayData)
176
    {
177
        $result = $this->convert($arrayData);
178
179
        $result->getMilestoneId()
180
            ->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Milestone\GithubMilestoneId');
181
        $result->getMilestone()
182
            ->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Milestone\GithubMilestoneSource');
183
    }
184
185
    /**
186
     * @dataProvider provideNonMilestonedIssues
187
     */
188
    public function it_will_have_null_for_issue_without_milestone_in_converted_result($arrayData)
189
    {
190
        $result = $this->convert($arrayData);
191
192
        $result->getMilestoneId()->shouldBe(null);
193
        $result->getMilestone()->shouldBe(null);
194
    }
195
196
    /**
197
     * @dataProvider provideAllIssues
198
     */
199
    public function it_will_have_comment_count_in_converted_result($arrayData)
200
    {
201
        $result = $this->convert($arrayData);
202
        $result->getCommentCount()->shouldBe($arrayData['comments']);
203
    }
204
205
    /**
206
     * @dataProvider provideAllIssues
207
     */
208
    public function it_will_have_github_created_datetime_in_converted_result($arrayData)
209
    {
210
        $result = $this->convert($arrayData);
211
212
        $result->getGithubCreatedAt()->shouldBeAnInstanceOf('DateTime');
213
        $result->getGithubCreatedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['created_at']);
214
    }
215
216
    /**
217
     * @dataProvider provideAllIssues
218
     */
219 View Code Duplication
    public function it_will_have_github_last_updated_datetime_in_converted_result($arrayData)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
220
    {
221
        $result = $this->convert($arrayData);
222
223
        $result->getGithubUpdatedAt()->shouldBeAnInstanceOf('DateTime');
224
        $result->getGithubUpdatedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['updated_at']);
225
    }
226
227
    /**
228
     * @dataProvider provideClosedIssues
229
     */
230 View Code Duplication
    public function it_will_have_github_closed_datetime_for_closed_milestones_in_converted_result($arrayData)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
231
    {
232
        $result = $this->convert($arrayData);
233
234
        $result->getGithubClosedAt()->shouldBeAnInstanceOf('DateTime');
235
        $result->getGithubClosedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['closed_at']);
236
    }
237
238
    public function provideAllIssues()
239
    {
240
        $testData = [];
241
242
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
243
            $testData[] = [$item];
244
        }
245
246
        return $testData;
247
    }
248
249
    public function provideOpenIssues()
250
    {
251
        $testData = [];
252
253
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
254
            if ('open' === $item['state']) {
255
                $testData[] = [$item];
256
            }
257
        }
258
259
        return $testData;
260
    }
261
262
    public function provideClosedIssues()
263
    {
264
        $testData = [];
265
266
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
267
            if ('closed' === $item['state']) {
268
                $testData[] = [$item];
269
            }
270
        }
271
272
        return $testData;
273
    }
274
275
    public function provideAssignedIssues()
276
    {
277
        $testData = [];
278
279
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
280
            if (null !== $item['assignee']) {
281
                $testData[] = [$item];
282
            }
283
        }
284
285
        return $testData;
286
    }
287
288
    public function provideNonAssignedIssues()
289
    {
290
        $testData = [];
291
292
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
293
            if (null === $item['assignee']) {
294
                $testData[] = [$item];
295
            }
296
        }
297
298
        return $testData;
299
    }
300
301
    public function provideMilestonedIssues()
302
    {
303
        $testData = [];
304
305
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
306
            if (null !== $item['milestone']) {
307
                $testData[] = [$item];
308
            }
309
        }
310
311
        return $testData;
312
    }
313
314
    public function provideNonMilestonedIssues()
315
    {
316
        $testData = [];
317
318
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
319
            if (null === $item['milestone']) {
320
                $testData[] = [$item];
321
            }
322
        }
323
324
        return $testData;
325
    }
326
327
    protected function getDataProvider()
328
    {
329
        return new JsonSampleDataProvider();
330
    }
331
}
332