Passed
Push — master ( c21964...371444 )
by Alessandro
01:05 queued 18s
created

TrelloBoardTest::testGetAllWithoutCards()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests;
4
5
6
use PHPUnit\Framework\TestCase;
7
use TrelloCycleTime\Client\TrelloApiClient;
8
use TrelloCycleTime\TrelloBoard;
9
10
class TrelloBoardTest extends TestCase
11
{
12
    public function testGetAllWithoutCards()
13
    {
14
        $client = $this->prophesize(TrelloApiClient::class);
15
        $boardId = 'boardId';
16
17
        $client->findAllCards($boardId)->willReturn([]);
18
19
        $trelloBoard = new TrelloBoard($client->reveal(), $boardId);
20
21
        $cycleTimes = $trelloBoard->getTransitions();
22
23
        $this->assertEquals([], $cycleTimes);
24
    }
25
26
    public function testGetAll()
27
    {
28
        $client = $this->prophesize(TrelloApiClient::class);
29
30
        $cardId = '5cdfb33499236c320e7d772c';
31
        $cards = [
32
            0 =>
33
                [
34
                    'id' => $cardId,
35
                    'checkItemStates' => NULL,
36
                    'closed' => false,
37
                    'dateLastActivity' => '2019-05-24T09:14:46.660Z',
38
                    'desc' => '',
39
                    'descData' => NULL,
40
                    'dueReminder' => NULL,
41
                    'idBoard' => '5cdfb328cc5d0542a9bc5ce0',
42
                    'idList' => '5cdfb33181899386ced12d14',
43
                    'idMembersVoted' => [],
44
                    'idShort' => 1,
45
                    'idAttachmentCover' => NULL,
46
                    'idLabels' => [],
47
                    'manualCoverAttachment' => false,
48
                    'name' => 'prima',
49
                    'pos' => 196607,
50
                    'shortLink' => 'jV1haDyb',
51
                    'badges' =>
52
                        [
53
                            'attachmentsByType' =>
54
                                [
55
                                    'trello' =>
56
                                        [
57
                                            'board' => 0,
58
                                            'card' => 0,
59
                                        ],
60
                                ],
61
                            'location' => false,
62
                            'votes' => 0,
63
                            'viewingMemberVoted' => false,
64
                            'subscribed' => false,
65
                            'fogbugz' => '',
66
                            'checkItems' => 0,
67
                            'checkItemsChecked' => 0,
68
                            'comments' => 0,
69
                            'attachments' => 0,
70
                            'description' => false,
71
                            'due' => NULL,
72
                            'dueComplete' => false,
73
                        ],
74
                    'dueComplete' => false,
75
                    'due' => NULL,
76
                    'idChecklists' => [],
77
                    'idMembers' => [],
78
                    'labels' => [],
79
                    'shortUrl' => 'https://trello.com/c/jV1haDyb',
80
                    'subscribed' => false,
81
                    'url' => 'https://trello.com/c/jV1haDyb/1-prima',
82
                ]
83
        ];
84
85
        $creationCard = [
86
            0 => [
87
                'id' => $cardId,
88
                'idMemberCreator' => '521dbcdd68ba6dec350040ff',
89
                'data' => [
90
                    'board' => [
91
                        'shortLink' => 'ZctgODOd',
92
                        'name' => 'TEST',
93
                        'id' => '5cdfb328cc5d0542a9bc5ce0'
94
                    ],
95
96
                    'list' => [
97
                        'name' => 'ToDo',
98
                        'id' => '5cdfb32f696b0a36d3186758'
99
                    ],
100
                    'card' => [
101
                        'shortLink' => 'tZEJWg0V',
102
                        'idShort' => '1',
103
                        'name' => 'prima',
104
                        'id' => $cardId
105
                    ]
106
                ],
107
                'type' => 'createCard',
108
                'date' => '2019-05-17T06:45:04.392Z',
109
                'limits' => [],
110
                'memberCreator' => [
111
                    'id' => '521dbcdd68ba6dec350040ff',
112
                    'avatarHash' => '3fab266d04a3f6f570b6a46606e133c0',
113
                    'avatarUrl' => 'https://trello-avatars.s3.amazonaws.com/3fab266d04a3f6f570b6a46606e133c0',
114
                    'fullName' => 'Alessandro Minoccheri',
115
                    'idMemberReferrer' => '516a8b285b342af34f003c96',
116
                    'initials' => 'AM'
117
                ]
118
            ]
119
        ];
120
121
        $cardHistory = json_decode('[
122
    {
123
        "id": "5ce7b60627e1bb5e0a8c60d1",
124
        "idMemberCreator": "521dbcdd68ba6dec350040ff",
125
        "data": {
126
            "listAfter": {
127
                "name": "DOne",
128
                "id": "5cdfb33181899386ced12d14"
129
            },
130
            "listBefore": {
131
                "name": "Doing",
132
                "id": "5cdfb3302e078d53fd5c01f8"
133
            },
134
            "board": {
135
                "shortLink": "ZctgODOd",
136
                "name": "TEST",
137
                "id": "5cdfb328cc5d0542a9bc5ce0"
138
            },
139
            "card": {
140
                "shortLink": "jV1haDyb",
141
                "idShort": 1,
142
                "name": "prima",
143
                "id": "5cdfb33499236c320e7d772c",
144
                "idList": "5cdfb33181899386ced12d14"
145
            },
146
            "old": {
147
                "idList": "5cdfb3302e078d53fd5c01f8"
148
            }
149
        },
150
        "type": "updateCard",
151
        "date": "2019-05-24T09:14:46.642Z",
152
        "limits": {},
153
        "memberCreator": {
154
            "id": "521dbcdd68ba6dec350040ff",
155
            "avatarHash": "3fab266d04a3f6f570b6a46606e133c0",
156
            "avatarUrl": "https://trello-avatars.s3.amazonaws.com/3fab266d04a3f6f570b6a46606e133c0",
157
            "fullName": "Alessandro Minoccheri",
158
            "idMemberReferrer": "516a8b285b342af34f003c96",
159
            "initials": "AM",
160
            "nonPublic": {},
161
            "nonPublicAvailable": false,
162
            "username": "alessandrominoccheri1"
163
        }
164
    },
165
    {
166
        "id": "5cdfb33a2d9abb38dcaedbd8",
167
        "idMemberCreator": "521dbcdd68ba6dec350040ff",
168
        "data": {
169
            "listAfter": {
170
                "name": "Doing",
171
                "id": "5cdfb3302e078d53fd5c01f8"
172
            },
173
            "listBefore": {
174
                "name": "ToDo",
175
                "id": "5cdfb32f696b0a36d3186758"
176
            },
177
            "board": {
178
                "shortLink": "ZctgODOd",
179
                "name": "TEST",
180
                "id": "5cdfb328cc5d0542a9bc5ce0"
181
            },
182
            "card": {
183
                "shortLink": "jV1haDyb",
184
                "idShort": 1,
185
                "name": "prima",
186
                "id": "5cdfb33499236c320e7d772c",
187
                "idList": "5cdfb3302e078d53fd5c01f8"
188
            },
189
            "old": {
190
                "idList": "5cdfb32f696b0a36d3186758"
191
            }
192
        },
193
        "type": "updateCard",
194
        "date": "2019-05-18T07:24:42.415Z",
195
        "limits": {},
196
        "memberCreator": {
197
            "id": "521dbcdd68ba6dec350040ff",
198
            "avatarHash": "3fab266d04a3f6f570b6a46606e133c0",
199
            "avatarUrl": "https://trello-avatars.s3.amazonaws.com/3fab266d04a3f6f570b6a46606e133c0",
200
            "fullName": "Alessandro Minoccheri",
201
            "idMemberReferrer": "516a8b285b342af34f003c96",
202
            "initials": "AM",
203
            "nonPublic": {},
204
            "nonPublicAvailable": false,
205
            "username": "alessandrominoccheri1"
206
        }
207
    }
208
]', true);
209
210
        $boardId = 'boardId';
211
212
        $client->findAllCards($boardId)->willReturn($cards);
213
214
        $client->findCreationCard($cardId)->willReturn($creationCard);
215
216
        $client->findAllCardHistory($cardId)->willReturn($cardHistory);
217
218
        $trelloBoard = new TrelloBoard($client->reveal(), $boardId);
219
220
        $cycleTimes = $trelloBoard->getTransitions();
221
222
        $expected = [0 => [
223
            'id' => '5cdfb33499236c320e7d772c',
224
            'title' => 'prima',
225
            'cycleTimes' => [
226
                0 => [
227
                    'from' => 'Doing',
228
                    'to' => 'DOne',
229
                    'days' => '6',
230
                    'name' => 'Doing_DOne'
231
                ],
232
                1 => [
233
                    'from' => 'ToDo',
234
                    'to' => 'Doing',
235
                    'days' => '1',
236
                    'name' => 'ToDo_Doing'
237
                ]
238
            ]
239
        ]
240
        ];
241
242
        $this->assertEquals($expected, $cycleTimes);
243
    }
244
}