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