1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use TrelloCycleTime\Collection\HistoryCards; |
7
|
|
|
use TrelloCycleTime\CycleTimeCalculator; |
8
|
|
|
use TrelloCycleTime\ValueObject\HistoryCard; |
9
|
|
|
use TrelloCycleTime\ValueObject\TimeCard; |
10
|
|
|
|
11
|
|
|
class CycleTimeCalculatorTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
private $historyCards; |
14
|
|
|
private $cycleTimeCalculator; |
15
|
|
|
|
16
|
|
|
public function setUp() |
17
|
|
|
{ |
18
|
|
|
$this->historyCards = $this->prophesize(HistoryCards::class); |
19
|
|
|
$this->cycleTimeCalculator = new CycleTimeCalculator([], $this->historyCards->reveal()); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testCalculateFromCardHistoryWithEmptyData() |
23
|
|
|
{ |
24
|
|
|
$historyCard = $this->prophesize(HistoryCard::class); |
25
|
|
|
$this->historyCards->getCardHistories()->willReturn([]); |
26
|
|
|
$this->cycleTimeCalculator->calculateFromCardHistory($historyCard->reveal()); |
|
|
|
|
27
|
|
|
|
28
|
|
|
$this->assertEquals([], $this->cycleTimeCalculator->getTimeCards()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public function testCalculateFromCardHistory() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$cardId = 1; |
34
|
|
|
$fromKey = 'from'; |
35
|
|
|
$toKey = 'to'; |
36
|
|
|
$fromDate = '2019-05-25 00:00:00'; |
37
|
|
|
$toDate = '2019-05-26 00:00:00'; |
38
|
|
|
|
39
|
|
|
$historyCard = $this->prophesize(HistoryCard::class); |
40
|
|
|
$historyCard->getId()->willReturn($cardId); |
41
|
|
|
$historyCard->getFrom()->willReturn($fromKey); |
42
|
|
|
$historyCard->getTo()->willReturn($toKey); |
43
|
|
|
|
44
|
|
|
$timeCard = $this->prophesize(TimeCard::class); |
45
|
|
|
$timeCard->getId()->willReturn($cardId); |
46
|
|
|
$timeCard->calculateDayDifferenceBetweenColumns($fromKey, $fromDate, $toKey, $toDate)->shouldBeCalled(); |
47
|
|
|
|
48
|
|
|
$this->historyCards->getCardHistories()->willReturn([$historyCard->reveal()]); |
49
|
|
|
$this->historyCards->getByCardIdAndTo($cardId, $fromKey)->willReturn($fromDate); |
50
|
|
|
$this->historyCards->getByCardIdAndTo($cardId, $toKey)->willReturn($toDate); |
51
|
|
|
|
52
|
|
|
$timeCardsCollection = [ |
53
|
|
|
$timeCard->reveal() |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
$this->cycleTimeCalculator = new CycleTimeCalculator($timeCardsCollection, $this->historyCards->reveal()); |
57
|
|
|
$this->cycleTimeCalculator->calculateFromCardHistory(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
View Code Duplication |
public function testCalculateWithStaticFromAndTo() |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$cardId = 1; |
63
|
|
|
$fromKey = 'from'; |
64
|
|
|
$toKey = 'to'; |
65
|
|
|
$fromDate = '2019-05-25 00:00:00'; |
66
|
|
|
$toDate = '2019-05-26 00:00:00'; |
67
|
|
|
|
68
|
|
|
$historyCard = $this->prophesize(HistoryCard::class); |
69
|
|
|
$historyCard->getId()->willReturn($cardId); |
70
|
|
|
$historyCard->getFrom()->willReturn($fromKey); |
71
|
|
|
$historyCard->getTo()->willReturn($toKey); |
72
|
|
|
|
73
|
|
|
$timeCard = $this->prophesize(TimeCard::class); |
74
|
|
|
$timeCard->getId()->willReturn($cardId); |
75
|
|
|
$timeCard->calculateDayDifferenceBetweenColumns($fromKey, $fromDate, $toKey, $toDate)->shouldBeCalled(); |
76
|
|
|
|
77
|
|
|
$this->historyCards->getCardHistories()->willReturn([$historyCard->reveal()]); |
78
|
|
|
$this->historyCards->getByCardIdAndTo($cardId, $fromKey)->willReturn($fromDate); |
79
|
|
|
$this->historyCards->getByCardIdAndTo($cardId, $toKey)->willReturn($toDate); |
80
|
|
|
|
81
|
|
|
$timeCardsCollection = [ |
82
|
|
|
$timeCard->reveal() |
83
|
|
|
]; |
84
|
|
|
|
85
|
|
|
$this->cycleTimeCalculator = new CycleTimeCalculator($timeCardsCollection, $this->historyCards->reveal()); |
86
|
|
|
$this->cycleTimeCalculator->calculateWithStaticFromAndTo($fromKey, $toKey); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testCalculateWithStaticFromAndToNull() |
90
|
|
|
{ |
91
|
|
|
$cardId = 1; |
92
|
|
|
$fromKey = null; |
93
|
|
|
$toKey = null; |
94
|
|
|
$fromDate = '2019-05-25 00:00:00'; |
95
|
|
|
$toDate = '2019-05-26 00:00:00'; |
96
|
|
|
|
97
|
|
|
$historyCard = $this->prophesize(HistoryCard::class); |
98
|
|
|
$historyCard->getId()->willReturn($cardId); |
99
|
|
|
$historyCard->getFrom()->willReturn($fromKey); |
100
|
|
|
$historyCard->getTo()->willReturn($toKey); |
101
|
|
|
|
102
|
|
|
$timeCard = $this->prophesize(TimeCard::class); |
103
|
|
|
$timeCard->getId()->willReturn($cardId); |
104
|
|
|
$timeCard->calculateDayDifferenceBetweenColumns($fromKey, $fromDate, $toKey, $toDate)->shouldNotBeCalled(); |
105
|
|
|
|
106
|
|
|
$this->historyCards->getCardHistories()->willReturn([$historyCard->reveal()]); |
107
|
|
|
$this->historyCards->getByCardIdAndTo($cardId, $fromKey)->willReturn($fromDate); |
108
|
|
|
$this->historyCards->getByCardIdAndTo($cardId, $toKey)->willReturn($toDate); |
109
|
|
|
|
110
|
|
|
$timeCardsCollection = [ |
111
|
|
|
$timeCard->reveal() |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
$this->cycleTimeCalculator = new CycleTimeCalculator($timeCardsCollection, $this->historyCards->reveal()); |
115
|
|
|
$this->cycleTimeCalculator->calculateWithStaticFromAndTo($fromKey, $toKey); |
116
|
|
|
} |
117
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.