Passed
Push — master ( 5ca0ef...7a5018 )
by Alessandro
01:44 queued 12s
created

HistoryCardsTest::testCreateReturnResults()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 95

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 95
rs 8.109
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\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