Completed
Push — master ( 12f683...a4b1f6 )
by Miro
02:28
created

GithubIssueConverterSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
namespace spec\DevBoardLib\GithubObjectApiFacade\Repo\Issue\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 GithubIssueConverterSpec extends ObjectBehavior
11
{
12
    public function it_is_initializable()
13
    {
14
        $this->shouldHaveType('DevBoardLib\GithubObjectApiFacade\Repo\Issue\Converter\GithubIssueConverter');
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 provideAllIssues
25
     */
26
    public function it_returns_github_issue_source_as_result($arrayData)
27
    {
28
        $this->convert($arrayData)
29
            ->shouldReturnAnInstanceOf('DevBoardLib\GithubObjectApiFacade\Repo\Issue\GithubIssueSource');
30
    }
31
32
    /**
33
     * @dataProvider provideAllIssues
34
     */
35
    public function it_will_have_repo_id_in_converted_result($arrayData)
36
    {
37
        $result = $this->convert($arrayData);
38
39
        //@TODO: How to test repo & id? (injecting does not work :( )
40
        $result->getRepoId()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Repo\GithubRepoId');
41
    }
42
43
    /**
44
     * @dataProvider provideAllIssues
45
     */
46
    public function it_will_have_repo_in_converted_result($arrayData)
47
    {
48
        $result = $this->convert($arrayData);
49
50
        //@TODO: How to test repo & id? (injecting does not work :( )
51
        $result->getRepo()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Repo\GithubRepo');
52
    }
53
54
    //
55
    //
56
    //
57
    //
58
59
    /**
60
     * @dataProvider provideAllIssues
61
     */
62
    public function it_will_have_issue_state_in_converted_result($arrayData)
63
    {
64
        $result = $this->convert($arrayData);
65
        $result->getState()->__toString()->shouldBe((string) $arrayData['state']);
66
        $result->getState()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Issue\State\GithubIssueState');
67
    }
68
69
    /**
70
     * @dataProvider provideOpenIssues
71
     */
72
    public function it_will_have_open_issue_state_in_converted_result($arrayData)
73
    {
74
        $result = $this->convert($arrayData);
75
        $result->getState()->__toString()->shouldBe('open');
76
        $result->getState()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Issue\State\GithubIssueOpenState');
77
    }
78
79
    /**
80
     * @dataProvider provideClosedIssues
81
     */
82
    public function it_will_have_closed_issue_state_in_converted_result($arrayData)
83
    {
84
        $result = $this->convert($arrayData);
85
        $result->getState()->__toString()->shouldBe('closed');
86
        $result->getState()->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Issue\State\GithubIssueClosedState');
87
    }
88
89
    /**
90
     * @dataProvider provideAllIssues
91
     */
92
    public function it_will_have_issue_title_in_converted_result($arrayData)
93
    {
94
        $result = $this->convert($arrayData);
95
        $result->getTitle()->shouldBe((string) $arrayData['title']);
96
    }
97
98
    /**
99
     * @dataProvider provideAllIssues
100
     */
101
    public function it_will_have_issue_description_in_converted_result($arrayData)
102
    {
103
        $result = $this->convert($arrayData);
104
        $result->getBody()->shouldBe((string) $arrayData['body']);
105
    }
106
107
    /**
108
     * @dataProvider provideAllIssues
109
     */
110
    public function it_will_have_user_id_of_creator_in_converted_result($arrayData)
111
    {
112
        $result = $this->convert($arrayData);
113
114
        $result->getCreatedByUserId()
115
            ->shouldBeAnInstanceOf('DevBoardLib\GithubCore\User\GithubUserId');
116
    }
117
118
    /**
119
     * @dataProvider provideAllIssues
120
     */
121
    public function it_will_have_creator_in_converted_result($arrayData)
122
    {
123
        $result = $this->convert($arrayData);
124
125
        $result->getCreatedByUser()
126
            ->shouldBeAnInstanceOf('DevBoardLib\GithubObjectApiFacade\User\GithubUserSource');
127
    }
128
129
    /**
130
     * @dataProvider provideAssignedIssues
131
     */
132
    public function it_will_have_user_id_of_assigned_user_in_converted_result($arrayData)
133
    {
134
        $result = $this->convert($arrayData);
135
136
        $result->getAssignedToUserId()
137
            ->shouldBeAnInstanceOf('DevBoardLib\GithubCore\User\GithubUserId');
138
    }
139
140
    /**
141
     * @dataProvider provideAssignedIssues
142
     */
143
    public function it_will_have_assigned_user_in_converted_result($arrayData)
144
    {
145
        $result = $this->convert($arrayData);
146
147
        $result->getAssignedToUser()
148
            ->shouldBeAnInstanceOf('DevBoardLib\GithubObjectApiFacade\User\GithubUserSource');
149
    }
150
151
    /**
152
     * @dataProvider provideNonAssignedIssues
153
     */
154
    public function it_will_have_null_for_user_id_on_unassigned_user_in_converted_result($arrayData)
155
    {
156
        $result = $this->convert($arrayData);
157
158
        $result->getAssignedToUserId()->shouldBe(null);
159
    }
160
161
    /**
162
     * @dataProvider provideNonAssignedIssues
163
     */
164
    public function it_will_have_null_for_user_on_unassigned_user_in_converted_result($arrayData)
165
    {
166
        $result = $this->convert($arrayData);
167
168
        $result->getAssignedToUser()->shouldBe(null);
169
    }
170
171
    /**
172
     * @dataProvider provideMilestonedIssues
173
     */
174
    public function it_will_have_milestone_in_converted_result($arrayData)
175
    {
176
        $result = $this->convert($arrayData);
177
178
        $result->getMilestoneId()
179
            ->shouldBeAnInstanceOf('DevBoardLib\GithubCore\Milestone\GithubMilestoneId');
180
        $result->getMilestone()
181
            ->shouldBeAnInstanceOf('DevBoardLib\GithubObjectApiFacade\Repo\Milestone\GithubMilestoneSource');
182
    }
183
184
    /**
185
     * @dataProvider provideNonMilestonedIssues
186
     */
187
    public function it_will_have_null_for_issue_without_milestone_in_converted_result($arrayData)
188
    {
189
        $result = $this->convert($arrayData);
190
191
        $result->getMilestoneId()->shouldBe(null);
192
        $result->getMilestone()->shouldBe(null);
193
    }
194
195
    /**
196
     * @dataProvider provideAllIssues
197
     */
198
    public function it_will_have_comment_count_in_converted_result($arrayData)
199
    {
200
        $result = $this->convert($arrayData);
201
        $result->getCommentCount()->shouldBe($arrayData['comments']);
202
    }
203
204
    /**
205
     * @dataProvider provideAllIssues
206
     */
207 View Code Duplication
    public function it_will_have_github_created_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...
208
    {
209
        $result = $this->convert($arrayData);
210
211
        $result->getGithubCreatedAt()->shouldBeAnInstanceOf('DateTime');
212
        $result->getGithubCreatedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['created_at']);
213
    }
214
215
    /**
216
     * @dataProvider provideAllIssues
217
     */
218 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...
219
    {
220
        $result = $this->convert($arrayData);
221
222
        $result->getGithubUpdatedAt()->shouldBeAnInstanceOf('DateTime');
223
        $result->getGithubUpdatedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['updated_at']);
224
    }
225
226
    /**
227
     * @dataProvider provideClosedIssues
228
     */
229 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...
230
    {
231
        $result = $this->convert($arrayData);
232
233
        $result->getGithubClosedAt()->shouldBeAnInstanceOf('DateTime');
234
        $result->getGithubClosedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['closed_at']);
235
    }
236
237
    public function provideAllIssues()
238
    {
239
        $testData = [];
240
241
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
242
            $testData[] = [$item];
243
        }
244
245
        return $testData;
246
    }
247
248
    public function provideOpenIssues()
249
    {
250
        $testData = [];
251
252
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
253
            if ('open' === $item['state']) {
254
                $testData[] = [$item];
255
            }
256
        }
257
258
        return $testData;
259
    }
260
261
    public function provideClosedIssues()
262
    {
263
        $testData = [];
264
265
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
266
            if ('closed' === $item['state']) {
267
                $testData[] = [$item];
268
            }
269
        }
270
271
        return $testData;
272
    }
273
274
    public function provideAssignedIssues()
275
    {
276
        $testData = [];
277
278
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
279
            if (null !== $item['assignee']) {
280
                $testData[] = [$item];
281
            }
282
        }
283
284
        return $testData;
285
    }
286
287
    public function provideNonAssignedIssues()
288
    {
289
        $testData = [];
290
291
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
292
            if (null === $item['assignee']) {
293
                $testData[] = [$item];
294
            }
295
        }
296
297
        return $testData;
298
    }
299
300
    public function provideMilestonedIssues()
301
    {
302
        $testData = [];
303
304
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
305
            if (null !== $item['milestone']) {
306
                $testData[] = [$item];
307
            }
308
        }
309
310
        return $testData;
311
    }
312
313
    public function provideNonMilestonedIssues()
314
    {
315
        $testData = [];
316
317
        foreach ($this->getDataProvider()->getAllIssues() as $item) {
318
            if (null === $item['milestone']) {
319
                $testData[] = [$item];
320
            }
321
        }
322
323
        return $testData;
324
    }
325
326
    protected function getDataProvider()
327
    {
328
        return new SampleDataProvider();
329
    }
330
}
331