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

GithubMilestoneConverterSpec   B

Complexity

Total Complexity 39

Size/Duplication

Total Lines 288
Duplicated Lines 7.29 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 39
c 1
b 0
f 1
lcom 1
cbo 3
dl 21
loc 288
rs 8.2857

28 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A let() 0 5 1
A it_returns_github_milestone_source_as_result() 0 5 1
A it_will_have_milestone_id_in_converted_result() 0 7 1
A it_will_have_repo_id_in_converted_result() 0 7 1
A it_will_have_repo_in_converted_result() 0 7 1
A it_will_have_milestone_number_in_converted_result() 0 5 1
A it_will_have_milestone_state_in_converted_result() 0 6 1
A it_will_have_open_milestone_state_in_converted_result() 0 6 1
A it_will_have_closed_milestone_state_in_converted_result() 0 6 1
A it_will_have_milestone_title_in_converted_result() 0 5 1
A it_will_have_milestone_description_in_converted_result() 0 5 1
A it_will_have_user_id_of_creator_in_converted_result() 0 7 1
A it_will_have_creator_in_converted_result() 0 7 1
A it_will_have_open_issue_count_in_converted_result() 0 5 1
A it_will_have_closed_issue_count_in_converted_result() 0 5 1
A it_will_have_due_date_in_converted_result() 0 9 2
A it_will_have_null_if_no_due_date_in_converted_result() 0 8 2
A it_will_have_github_created_datetime_in_converted_result() 7 7 1
A it_will_have_github_last_updated_datetime_in_converted_result() 7 7 1
A it_will_have_github_closed_datetime_for_closed_milestones_in_converted_result() 7 7 1
A it_will_have_null_for_github_closed_datetime_on_open_milestones_in_converted_result() 0 6 1
A provideAllMilestones() 0 10 2
A provideOpenMilestones() 0 12 3
A provideClosedMilestones() 0 12 3
A provideMilestonesWithDueDate() 0 12 3
A provideMilestonesWithOutDueDate() 0 12 3
A getDataProvider() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\GithubObjectApiFacade\Repo\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 provideAllMilestones
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 provideAllMilestones
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\GithubObjectApiFacade\User\GithubUserSource');
142
    }
143
144
    /**
145
     * @dataProvider provideAllMilestones
146
     */
147
    public function it_will_have_open_issue_count_in_converted_result($arrayData)
148
    {
149
        $result = $this->convert($arrayData);
150
        $result->getOpenIssueCount()->shouldBe($arrayData['open_issues']);
151
    }
152
153
    /**
154
     * @dataProvider provideAllMilestones
155
     */
156
    public function it_will_have_closed_issue_count_in_converted_result($arrayData)
157
    {
158
        $result = $this->convert($arrayData);
159
        $result->getClosedIssueCount()->shouldBe($arrayData['closed_issues']);
160
    }
161
162
    /**
163
     * @dataProvider provideMilestonesWithDueDate
164
     */
165
    public function it_will_have_due_date_in_converted_result($arrayData)
166
    {
167
        $result = $this->convert($arrayData);
168
169
        if (null !== $arrayData['due_on']) {
170
            $result->getDueDate()->shouldBeAnInstanceOf('DateTime');
171
            $result->getDueDate()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['due_on']);
172
        }
173
    }
174
175
    /**
176
     * @dataProvider provideMilestonesWithOutDueDate
177
     */
178
    public function it_will_have_null_if_no_due_date_in_converted_result($arrayData)
179
    {
180
        $result = $this->convert($arrayData);
181
182
        if (null === $arrayData['due_on']) {
183
            $result->getDueDate()->shouldBe(null);
184
        }
185
    }
186
187
    /**
188
     * @dataProvider provideAllMilestones
189
     */
190 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...
191
    {
192
        $result = $this->convert($arrayData);
193
194
        $result->getGithubCreatedAt()->shouldBeAnInstanceOf('DateTime');
195
        $result->getGithubCreatedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['created_at']);
196
    }
197
198
    /**
199
     * @dataProvider provideAllMilestones
200
     */
201 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...
202
    {
203
        $result = $this->convert($arrayData);
204
205
        $result->getGithubUpdatedAt()->shouldBeAnInstanceOf('DateTime');
206
        $result->getGithubUpdatedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['updated_at']);
207
    }
208
209
    /**
210
     * @dataProvider provideClosedMilestones
211
     */
212 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...
213
    {
214
        $result = $this->convert($arrayData);
215
216
        $result->getGithubClosedAt()->shouldBeAnInstanceOf('DateTime');
217
        $result->getGithubClosedAt()->format('Y-m-d\TH:i:s\Z')->shouldBe($arrayData['closed_at']);
218
    }
219
220
    /**
221
     * @dataProvider provideOpenMilestones
222
     */
223
    public function it_will_have_null_for_github_closed_datetime_on_open_milestones_in_converted_result($arrayData)
224
    {
225
        $result = $this->convert($arrayData);
226
227
        $result->getGithubClosedAt()->shouldBe(null);
228
    }
229
230
    public function provideAllMilestones()
231
    {
232
        $testData = [];
233
234
        foreach ($this->getDataProvider()->getAllMilestones() as $item) {
235
            $testData[] = [$item];
236
        }
237
238
        return $testData;
239
    }
240
241
    public function provideOpenMilestones()
242
    {
243
        $testData = [];
244
245
        foreach ($this->getDataProvider()->getAllMilestones() as $item) {
246
            if ('open' === $item['state']) {
247
                $testData[] = [$item];
248
            }
249
        }
250
251
        return $testData;
252
    }
253
254
    public function provideClosedMilestones()
255
    {
256
        $testData = [];
257
258
        foreach ($this->getDataProvider()->getAllMilestones() as $item) {
259
            if ('closed' === $item['state']) {
260
                $testData[] = [$item];
261
            }
262
        }
263
264
        return $testData;
265
    }
266
267
    public function provideMilestonesWithDueDate()
268
    {
269
        $testData = [];
270
271
        foreach ($this->getDataProvider()->getAllMilestones() as $item) {
272
            if (null !== $item['due_on']) {
273
                $testData[] = [$item];
274
            }
275
        }
276
277
        return $testData;
278
    }
279
280
    public function provideMilestonesWithOutDueDate()
281
    {
282
        $testData = [];
283
284
        foreach ($this->getDataProvider()->getAllMilestones() as $item) {
285
            if (null === $item['due_on']) {
286
                $testData[] = [$item];
287
            }
288
        }
289
290
        return $testData;
291
    }
292
293
    protected function getDataProvider()
294
    {
295
        return new SampleDataProvider();
296
    }
297
}
298