1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Collection; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use TrelloCycleTime\Client\TrelloApiClient; |
7
|
|
|
use TrelloCycleTime\Collection\HistoryCards; |
8
|
|
|
use TrelloCycleTime\ValueObject\HistoryCard; |
9
|
|
|
|
10
|
|
|
class HistoryCardsTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
private $client; |
13
|
|
|
|
14
|
|
|
public function setup() |
15
|
|
|
{ |
16
|
|
|
$this->client = $this->prophesize(TrelloApiClient::class); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testCreateWithoutResultsReturnEmptyArray() |
20
|
|
|
{ |
21
|
|
|
$cardHistoryCollection = HistoryCards::createFromCards($this->client->reveal(), []); |
22
|
|
|
$this->assertEquals([], $cardHistoryCollection->getCardHistories()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testCreateReturnResults() |
26
|
|
|
{ |
27
|
|
|
$cardId = '1000'; |
28
|
|
|
$name = 'name'; |
29
|
|
|
$listBefore = 'listBefore'; |
30
|
|
|
$listAfter = 'listAfter'; |
31
|
|
|
$date = '2019-04-29 00:00:00'; |
32
|
|
|
$name2 = 'name2'; |
33
|
|
|
$listBefore2 = 'listBefore2'; |
34
|
|
|
$listAfter2 = 'listAfter2'; |
35
|
|
|
$date2 = '2019-04-29 10:00:00'; |
36
|
|
|
|
37
|
|
|
$cards = [ |
38
|
|
|
[ |
39
|
|
|
'id' => $cardId |
40
|
|
|
] |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
$data = [ |
44
|
|
|
[ |
45
|
|
|
'id' => $cardId, |
46
|
|
|
'data' => [ |
47
|
|
|
'card' => [ |
48
|
|
|
'id' => $cardId, |
49
|
|
|
'name' => $name, |
50
|
|
|
], |
51
|
|
|
'listBefore' => [ |
52
|
|
|
'name' => $listBefore, |
53
|
|
|
], |
54
|
|
|
'listAfter' => [ |
55
|
|
|
'name' => $listAfter, |
56
|
|
|
] |
57
|
|
|
], |
58
|
|
|
'date' => $date |
59
|
|
|
], |
60
|
|
|
[ |
61
|
|
|
'id' => $cardId, |
62
|
|
|
'data' => [ |
63
|
|
|
'card' => [ |
64
|
|
|
'id' => $cardId, |
65
|
|
|
'name' => $name2, |
66
|
|
|
], |
67
|
|
|
'listBefore' => [ |
68
|
|
|
'name' => $listBefore2, |
69
|
|
|
], |
70
|
|
|
'listAfter' => [ |
71
|
|
|
'name' => $listAfter2, |
72
|
|
|
] |
73
|
|
|
], |
74
|
|
|
'date' => $date2 |
75
|
|
|
] |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
$this->client->findCreationCard($cardId)->willReturn([]); |
79
|
|
|
$this->client->findAllCardHistory($cardId)->willReturn($data); |
80
|
|
|
$cardHistoryCollection = HistoryCards::createFromCards($this->client->reveal(), $cards); |
81
|
|
|
|
82
|
|
|
$cardHistory = HistoryCard::createFromArray([ |
83
|
|
|
'id' => $cardId, |
84
|
|
|
'data' => [ |
85
|
|
|
'card' => [ |
86
|
|
|
'id' => $cardId, |
87
|
|
|
'name' => $name, |
88
|
|
|
], |
89
|
|
|
'listBefore' => [ |
90
|
|
|
'name' => $listBefore, |
91
|
|
|
], |
92
|
|
|
'listAfter' => [ |
93
|
|
|
'name' => $listAfter, |
94
|
|
|
] |
95
|
|
|
], |
96
|
|
|
'date' => $date |
97
|
|
|
]); |
98
|
|
|
|
99
|
|
|
$cardHistory2 = HistoryCard::createFromArray([ |
100
|
|
|
'id' => $cardId, |
101
|
|
|
'data' => [ |
102
|
|
|
'card' => [ |
103
|
|
|
'id' => $cardId, |
104
|
|
|
'name' => $name2, |
105
|
|
|
], |
106
|
|
|
'listBefore' => [ |
107
|
|
|
'name' => $listBefore2, |
108
|
|
|
], |
109
|
|
|
'listAfter' => [ |
110
|
|
|
'name' => $listAfter2, |
111
|
|
|
] |
112
|
|
|
], |
113
|
|
|
'date' => $date2 |
114
|
|
|
]); |
115
|
|
|
|
116
|
|
|
$expected = [$cardHistory, $cardHistory2]; |
117
|
|
|
$histories = $cardHistoryCollection->getCardHistories(); |
118
|
|
|
$this->assertEquals($expected, $histories); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|