Passed
Push — master ( 7a5018...5ee49d )
by Alessandro
01:01 queued 10s
created

TrelloBoardTest::testGetTransitions()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 218

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 218
rs 8
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Tests;
4
5
6
use PHPUnit\Framework\TestCase;
7
use TrelloCycleTime\Client\TrelloApiClient;
8
use TrelloCycleTime\Collection\CardsIdCollection;
9
use TrelloCycleTime\TrelloBoard;
10
11
class TrelloBoardTest extends TestCase
12
{
13
    public function testGetAllWithoutCards()
14
    {
15
        $client = $this->prophesize(TrelloApiClient::class);
16
        $boardId = 'boardId';
17
18
        $client->findAllCards($boardId)->willReturn([]);
19
20
        $trelloBoard = new TrelloBoard($client->reveal(), $boardId);
21
22
        $cycleTimes = $trelloBoard->getTransitions();
23
24
        $this->assertEquals([], $cycleTimes);
25
    }
26
27
    public function testGetTransitions()
28
    {
29
        $client = $this->prophesize(TrelloApiClient::class);
30
31
        $cardId = '5cdfb33499236c320e7d772c';
32
        $cards = [
33
            0 =>
34
                [
35
                    'id' => $cardId,
36
                    'checkItemStates' => NULL,
37
                    'closed' => false,
38
                    'dateLastActivity' => '2019-05-24T09:14:46.660Z',
39
                    'desc' => '',
40
                    'descData' => NULL,
41
                    'dueReminder' => NULL,
42
                    'idBoard' => '5cdfb328cc5d0542a9bc5ce0',
43
                    'idList' => '5cdfb33181899386ced12d14',
44
                    'idMembersVoted' => [],
45
                    'idShort' => 1,
46
                    'idAttachmentCover' => NULL,
47
                    'idLabels' => [],
48
                    'manualCoverAttachment' => false,
49
                    'name' => 'prima',
50
                    'pos' => 196607,
51
                    'shortLink' => 'jV1haDyb',
52
                    'badges' =>
53
                        [
54
                            'attachmentsByType' =>
55
                                [
56
                                    'trello' =>
57
                                        [
58
                                            'board' => 0,
59
                                            'card' => 0,
60
                                        ],
61
                                ],
62
                            'location' => false,
63
                            'votes' => 0,
64
                            'viewingMemberVoted' => false,
65
                            'subscribed' => false,
66
                            'fogbugz' => '',
67
                            'checkItems' => 0,
68
                            'checkItemsChecked' => 0,
69
                            'comments' => 0,
70
                            'attachments' => 0,
71
                            'description' => false,
72
                            'due' => NULL,
73
                            'dueComplete' => false,
74
                        ],
75
                    'dueComplete' => false,
76
                    'due' => NULL,
77
                    'idChecklists' => [],
78
                    'idMembers' => [],
79
                    'labels' => [],
80
                    'shortUrl' => 'https://trello.com/c/jV1haDyb',
81
                    'subscribed' => false,
82
                    'url' => 'https://trello.com/c/jV1haDyb/1-prima',
83
                ]
84
        ];
85
86
        $creationCard = [
87
            0 => [
88
                'id' => $cardId,
89
                'idMemberCreator' => '521dbcdd68ba6dec350040ff',
90
                'data' => [
91
                    'board' => [
92
                        'shortLink' => 'ZctgODOd',
93
                        'name' => 'TEST',
94
                        'id' => '5cdfb328cc5d0542a9bc5ce0'
95
                    ],
96
97
                    'list' => [
98
                        'name' => 'ToDo',
99
                        'id' => '5cdfb32f696b0a36d3186758'
100
                    ],
101
                    'card' => [
102
                        'shortLink' => 'tZEJWg0V',
103
                        'idShort' => '1',
104
                        'name' => 'prima',
105
                        'id' => $cardId
106
                    ]
107
                ],
108
                'type' => 'createCard',
109
                'date' => '2019-05-17T06:45:04.392Z',
110
                'limits' => [],
111
                'memberCreator' => [
112
                    'id' => '521dbcdd68ba6dec350040ff',
113
                    'avatarHash' => '3fab266d04a3f6f570b6a46606e133c0',
114
                    'avatarUrl' => 'https://trello-avatars.s3.amazonaws.com/3fab266d04a3f6f570b6a46606e133c0',
115
                    'fullName' => 'Alessandro Minoccheri',
116
                    'idMemberReferrer' => '516a8b285b342af34f003c96',
117
                    'initials' => 'AM'
118
                ]
119
            ]
120
        ];
121
122
        $cardHistory = json_decode('[
123
    {
124
        "id": "5ce7b60627e1bb5e0a8c60d1",
125
        "idMemberCreator": "521dbcdd68ba6dec350040ff",
126
        "data": {
127
            "listAfter": {
128
                "name": "DOne",
129
                "id": "5cdfb33181899386ced12d14"
130
            },
131
            "listBefore": {
132
                "name": "Doing",
133
                "id": "5cdfb3302e078d53fd5c01f8"
134
            },
135
            "board": {
136
                "shortLink": "ZctgODOd",
137
                "name": "TEST",
138
                "id": "5cdfb328cc5d0542a9bc5ce0"
139
            },
140
            "card": {
141
                "shortLink": "jV1haDyb",
142
                "idShort": 1,
143
                "name": "prima",
144
                "id": "5cdfb33499236c320e7d772c",
145
                "idList": "5cdfb33181899386ced12d14"
146
            },
147
            "old": {
148
                "idList": "5cdfb3302e078d53fd5c01f8"
149
            }
150
        },
151
        "type": "updateCard",
152
        "date": "2019-05-24T09:14:46.642Z",
153
        "limits": {},
154
        "memberCreator": {
155
            "id": "521dbcdd68ba6dec350040ff",
156
            "avatarHash": "3fab266d04a3f6f570b6a46606e133c0",
157
            "avatarUrl": "https://trello-avatars.s3.amazonaws.com/3fab266d04a3f6f570b6a46606e133c0",
158
            "fullName": "Alessandro Minoccheri",
159
            "idMemberReferrer": "516a8b285b342af34f003c96",
160
            "initials": "AM",
161
            "nonPublic": {},
162
            "nonPublicAvailable": false,
163
            "username": "alessandrominoccheri1"
164
        }
165
    },
166
    {
167
        "id": "5cdfb33a2d9abb38dcaedbd8",
168
        "idMemberCreator": "521dbcdd68ba6dec350040ff",
169
        "data": {
170
            "listAfter": {
171
                "name": "Doing",
172
                "id": "5cdfb3302e078d53fd5c01f8"
173
            },
174
            "listBefore": {
175
                "name": "ToDo",
176
                "id": "5cdfb32f696b0a36d3186758"
177
            },
178
            "board": {
179
                "shortLink": "ZctgODOd",
180
                "name": "TEST",
181
                "id": "5cdfb328cc5d0542a9bc5ce0"
182
            },
183
            "card": {
184
                "shortLink": "jV1haDyb",
185
                "idShort": 1,
186
                "name": "prima",
187
                "id": "5cdfb33499236c320e7d772c",
188
                "idList": "5cdfb3302e078d53fd5c01f8"
189
            },
190
            "old": {
191
                "idList": "5cdfb32f696b0a36d3186758"
192
            }
193
        },
194
        "type": "updateCard",
195
        "date": "2019-05-18T07:24:42.415Z",
196
        "limits": {},
197
        "memberCreator": {
198
            "id": "521dbcdd68ba6dec350040ff",
199
            "avatarHash": "3fab266d04a3f6f570b6a46606e133c0",
200
            "avatarUrl": "https://trello-avatars.s3.amazonaws.com/3fab266d04a3f6f570b6a46606e133c0",
201
            "fullName": "Alessandro Minoccheri",
202
            "idMemberReferrer": "516a8b285b342af34f003c96",
203
            "initials": "AM",
204
            "nonPublic": {},
205
            "nonPublicAvailable": false,
206
            "username": "alessandrominoccheri1"
207
        }
208
    }
209
]', true);
210
211
        $boardId = 'boardId';
212
213
        $client->findAllCards($boardId)->willReturn($cards);
214
215
        $client->findCreationCard($cardId)->willReturn($creationCard);
216
217
        $client->findAllCardHistory($cardId)->willReturn($cardHistory);
218
219
        $trelloBoard = new TrelloBoard($client->reveal(), $boardId);
220
221
        $cycleTimes = $trelloBoard->getTransitions();
222
223
        $expected = [0 => [
224
            'id' => '5cdfb33499236c320e7d772c',
225
            'title' => 'prima',
226
            'cycleTimes' => [
227
                0 => [
228
                    'from' => 'Doing',
229
                    'to' => 'DOne',
230
                    'days' => '6',
231
                    'name' => 'Doing_DOne'
232
                ],
233
                1 => [
234
                    'from' => 'ToDo',
235
                    'to' => 'Doing',
236
                    'days' => '1',
237
                    'name' => 'ToDo_Doing'
238
                ]
239
            ]
240
        ]
241
        ];
242
243
        $this->assertEquals($expected, $cycleTimes);
244
    }
245
246
    public function testGetCardTransitions()
247
    {
248
        $client = $this->prophesize(TrelloApiClient::class);
249
250
        $id = '5cdfb33499236c320e7d772c';
251
252
        $creationCard = [
253
            0 => [
254
                'id' => $id,
255
                'idMemberCreator' => '521dbcdd68ba6dec350040ff',
256
                'data' => [
257
                    'board' => [
258
                        'shortLink' => 'ZctgODOd',
259
                        'name' => 'TEST',
260
                        'id' => '5cdfb328cc5d0542a9bc5ce0'
261
                    ],
262
263
                    'list' => [
264
                        'name' => 'ToDo',
265
                        'id' => '5cdfb32f696b0a36d3186758'
266
                    ],
267
                    'card' => [
268
                        'shortLink' => 'tZEJWg0V',
269
                        'idShort' => '1',
270
                        'name' => 'prima',
271
                        'id' => $id
272
                    ]
273
                ],
274
                'type' => 'createCard',
275
                'date' => '2019-05-17T06:45:04.392Z',
276
                'limits' => [],
277
                'memberCreator' => [
278
                    'id' => '521dbcdd68ba6dec350040ff',
279
                    'avatarHash' => '3fab266d04a3f6f570b6a46606e133c0',
280
                    'avatarUrl' => 'https://trello-avatars.s3.amazonaws.com/3fab266d04a3f6f570b6a46606e133c0',
281
                    'fullName' => 'Alessandro Minoccheri',
282
                    'idMemberReferrer' => '516a8b285b342af34f003c96',
283
                    'initials' => 'AM'
284
                ]
285
            ]
286
        ];
287
288
289
        $cardHistory = json_decode('[
290
    {
291
        "id": "5ce7b60627e1bb5e0a8c60d1",
292
        "idMemberCreator": "521dbcdd68ba6dec350040ff",
293
        "data": {
294
            "listAfter": {
295
                "name": "DOne",
296
                "id": "5cdfb33181899386ced12d14"
297
            },
298
            "listBefore": {
299
                "name": "Doing",
300
                "id": "5cdfb3302e078d53fd5c01f8"
301
            },
302
            "board": {
303
                "shortLink": "ZctgODOd",
304
                "name": "TEST",
305
                "id": "5cdfb328cc5d0542a9bc5ce0"
306
            },
307
            "card": {
308
                "shortLink": "jV1haDyb",
309
                "idShort": 1,
310
                "name": "prima",
311
                "id": "5cdfb33499236c320e7d772c",
312
                "idList": "5cdfb33181899386ced12d14"
313
            },
314
            "old": {
315
                "idList": "5cdfb3302e078d53fd5c01f8"
316
            }
317
        },
318
        "type": "updateCard",
319
        "date": "2019-05-24T09:14:46.642Z",
320
        "limits": {},
321
        "memberCreator": {
322
            "id": "521dbcdd68ba6dec350040ff",
323
            "avatarHash": "3fab266d04a3f6f570b6a46606e133c0",
324
            "avatarUrl": "https://trello-avatars.s3.amazonaws.com/3fab266d04a3f6f570b6a46606e133c0",
325
            "fullName": "Alessandro Minoccheri",
326
            "idMemberReferrer": "516a8b285b342af34f003c96",
327
            "initials": "AM",
328
            "nonPublic": {},
329
            "nonPublicAvailable": false,
330
            "username": "alessandrominoccheri1"
331
        }
332
    },
333
    {
334
        "id": "5cdfb33a2d9abb38dcaedbd8",
335
        "idMemberCreator": "521dbcdd68ba6dec350040ff",
336
        "data": {
337
            "listAfter": {
338
                "name": "Doing",
339
                "id": "5cdfb3302e078d53fd5c01f8"
340
            },
341
            "listBefore": {
342
                "name": "ToDo",
343
                "id": "5cdfb32f696b0a36d3186758"
344
            },
345
            "board": {
346
                "shortLink": "ZctgODOd",
347
                "name": "TEST",
348
                "id": "5cdfb328cc5d0542a9bc5ce0"
349
            },
350
            "card": {
351
                "shortLink": "jV1haDyb",
352
                "idShort": 1,
353
                "name": "prima",
354
                "id": "5cdfb33499236c320e7d772c",
355
                "idList": "5cdfb3302e078d53fd5c01f8"
356
            },
357
            "old": {
358
                "idList": "5cdfb32f696b0a36d3186758"
359
            }
360
        },
361
        "type": "updateCard",
362
        "date": "2019-05-18T07:24:42.415Z",
363
        "limits": {},
364
        "memberCreator": {
365
            "id": "521dbcdd68ba6dec350040ff",
366
            "avatarHash": "3fab266d04a3f6f570b6a46606e133c0",
367
            "avatarUrl": "https://trello-avatars.s3.amazonaws.com/3fab266d04a3f6f570b6a46606e133c0",
368
            "fullName": "Alessandro Minoccheri",
369
            "idMemberReferrer": "516a8b285b342af34f003c96",
370
            "initials": "AM",
371
            "nonPublic": {},
372
            "nonPublicAvailable": false,
373
            "username": "alessandrominoccheri1"
374
        }
375
    }
376
]', true);
377
378
        $boardId = 'boardId';
379
380
        $client->findCreationCard($id)->willReturn($creationCard);
381
382
        $client->findAllCardHistory($id)->willReturn($cardHistory);
383
384
        $trelloBoard = new TrelloBoard($client->reveal(), $boardId);
385
386
        $cycleTimes = $trelloBoard->getCardTransitions($id);
387
388
        $expected = [0 => [
389
            'id' => $id,
390
            'title' => 'prima',
391
            'cycleTimes' => [
392
                0 => [
393
                    'from' => 'Doing',
394
                    'to' => 'DOne',
395
                    'days' => '6',
396
                    'name' => 'Doing_DOne'
397
                ],
398
                1 => [
399
                    'from' => 'ToDo',
400
                    'to' => 'Doing',
401
                    'days' => '1',
402
                    'name' => 'ToDo_Doing'
403
                ]
404
            ]
405
        ]
406
        ];
407
408
        $this->assertEquals($expected, $cycleTimes);
409
    }
410
}