Completed
Push — master ( 5f50d9...cf27fb )
by Vladimir
02:07
created

PulseBoardTestCase::testGroupOfPulseWithApiCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace allejo\DaPulse\Tests;
4
5
use allejo\DaPulse\Exceptions\ArgumentMismatchException;
6
use allejo\DaPulse\Exceptions\InvalidArraySizeException;
7
use allejo\DaPulse\Exceptions\InvalidColumnException;
8
use allejo\DaPulse\Exceptions\InvalidObjectException;
9
use allejo\DaPulse\Objects\PulseColumnStatusValue;
10
use allejo\DaPulse\Pulse;
11
use allejo\DaPulse\PulseBoard;
12
use allejo\DaPulse\PulseColumn;
13
use allejo\DaPulse\PulseGroup;
14
15
class PulseBoardTestCase extends PulseUnitTestCase
16
{
17
    private $id;
18
19
    /**
20
     * @var PulseBoard
21
     */
22
    private $board;
23
24
    /**
25
     * @var Pulse[]
26
     */
27
    private $pulses;
28
29
    public function setUp()
30
    {
31
        parent::setUp();
32
33
        $this->id = 3844236;
34
        $this->board = new PulseBoard($this->id);
35
        $this->pulses = $this->board->getPulses();
36
    }
37
38
    public function testGetBoardUrl()
39
    {
40
        $expectedURL = "https://phppulse.dapulse.com/boards/" . $this->id;
41
        $this->assertEquals($expectedURL, $this->board->getUrl());
42
    }
43
44
    public function testGetBoardId()
45
    {
46
        $this->assertEquals($this->id, $this->board->getId());
47
    }
48
49
    public function testGetBoardName()
50
    {
51
        $expectedValue = "API Mocks";
52
        $this->assertEquals($expectedValue, $this->board->getName());
53
    }
54
55
    public function testGetBoardDescription()
56
    {
57
        $expectedValue = "A DaPulse board used for unit testing and providing mocks for the PhpPulse library we use and maintain";
58
        $this->assertEquals($expectedValue, $this->board->getDescription());
59
    }
60
61
    public function testGetBoardColumnsCount()
62
    {
63
        $this->assertCountGreaterThan(0, $this->board->getColumns());
64
    }
65
66
    public function testGetBoardColumnsType()
67
    {
68
        $column = $this->board->getColumns();
69
70
        $this->assertInstanceOf(PulseColumn::class, $column[0]);
71
    }
72
73
    public function testGetBoardGroupType()
74
    {
75
        $group = $this->board->getGroups();
76
77
        $this->assertInstanceOf(PulseGroup::class, $group[0]);
78
    }
79
80
    public function testGetBoardCreatedAt()
81
    {
82
        $this->assertInstanceOf(\DateTime::class, $this->board->getCreatedAt());
83
    }
84
85
    public function testGetBoardUpdatedAt()
86
    {
87
        $this->assertInstanceOf(\DateTime::class, $this->board->getUpdatedAt());
88
    }
89
90
    public function testGetPulses()
91
    {
92
        $this->assertCountEqual(4, $this->pulses);
93
    }
94
95
    public function testGroupOfPulseWithApiCall()
96
    {
97
        $newPulse = new Pulse(27157096);
98
99
        $this->assertEquals('topics', $newPulse->getGroupId());
100
    }
101
102
    public function testGetBoardColumns()
103
    {
104
        $columns = $this->board->getColumns();
105
106
        $this->assertIsArray($columns);
107
        $this->assertCount(8, $columns); // 6 custom columns + "name" + "last update"
108
        $this->assertInstanceOf(PulseColumn::class, $columns[0]);
109
    }
110
111
    public function testGetBoardStatusColumnLabels()
112
    {
113
        $columns = $this->board->getColumns();
114
        $labels = $columns[2]->getLabels();
115
116
        $this->assertCount(11, $labels);
117
    }
118
119
    public function testGetBoardTextColumnLabelsThrowsException()
120
    {
121
        $this->setExpectedException(InvalidColumnException::class);
122
123
        $columns = $this->board->getColumns();
124
        $columns[0]->getLabels();
125
    }
126
127
    public function testGetBoardGroups()
128
    {
129
        $groups = $this->board->getGroups();
130
131
        $this->assertIsArray($groups);
132
        $this->assertCount(2, $groups);
133
        $this->assertInstanceOf(PulseGroup::class, $groups[0]);
134
135
        $group_one = $groups[0];
136
        $this->assertEquals('#037f4c', $group_one->getColor());
137
        $this->assertEquals('Group One', $group_one->getTitle());
138
        $this->assertEquals($this->board->getId(), $group_one->getBoardId());
139
    }
140
141
    public function testGetBoardGroupsIncludingArchived()
142
    {
143
        $groups = $this->board->getGroups(true);
144
145
        $this->assertIsArray($groups);
146
        $this->assertCount(3, $groups);
147
        $this->assertInstanceOf(PulseGroup::class, $groups[0]);
148
        $this->assertTrue($groups[2]->isArchived());
149
    }
150
151
    public function testBoardCreateStatusColumn()
152
    {
153
        $board = new PulseBoard(27168881, true);
154
        $board->createColumn('Overall Status', PulseColumn::Status, [
155
            PulseColumnStatusValue::Gold  => 'Warning',
156
            PulseColumnStatusValue::Green => 'Success'
157
        ]);
158
159
        $columns = $board->getColumns();
160
        $this->assertCount(9, $columns);
161
    }
162
163
    public function testBoardCreateTextColumnWithLabelsThrowsException()
164
    {
165
        $this->setExpectedException(ArgumentMismatchException::class);
166
167
        $board = new PulseBoard(27168881, true);
168
        $board->createColumn('Super Toast', PulseColumn::Text, [
169
            'toaster'
170
        ]);
171
    }
172
173
    public function testBoardCreateStatusColumnWithInvalidColumns()
174
    {
175
        $this->setExpectedException(InvalidArraySizeException::class);
176
177
        $board = new PulseBoard(27168881, true);
178
        $board->createColumn('Project Status', PulseColumn::Status, [
179
            0  => 'Success!',
180
            11 => 'Crashed and burned'
181
        ]);
182
    }
183
184
    public function testBoardCreateGroup()
185
    {
186
        $boardID = 27168881;
187
        $title = 'My new group';
188
        $board = new PulseBoard($boardID, true);
189
        $group = $board->createGroup($title);
190
191
        $this->assertInstanceOf(PulseGroup::class, $group);
192
        $this->assertEquals($title, $group->getTitle());
193
        $this->assertEquals($boardID, $group->getBoardId());
194
        $this->assertFalse($group->isArchived());
195
        $this->assertFalse($group->isDeleted());
196
    }
197
198
    public function testBoardDeleteGroup()
199
    {
200
        $groupID = 'my_new_group';
201
        $board = new PulseBoard(27168881, true);
202
        $groups = $board->deleteGroup($groupID);
203
204
        foreach ($groups as $group)
205
        {
206
            if ($group->getId() == $groupID)
207
            {
208
                $this->assertTrue($group->isArchived());
209
                break;
210
            }
211
        }
212
    }
213
214
    public function testBoardCreatePulse()
215
    {
216
        $title = 'Turn off the lights';
217
        $board = new PulseBoard(27168881);
218
        $pulse = $board->createPulse($title, self::MainUser);
219
220
        $this->assertEquals(self::MainUser, $pulse->getSubscribers()[0]->getId());
221
        $this->assertEquals($title, $pulse->getName());
222
        $this->assertEquals($board->getId(), $pulse->getBoardId());
223
        $this->assertEquals('topics', $pulse->getGroupId());
224
    }
225
226 View Code Duplication
    public function testBoardCreation()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
227
    {
228
        $name = 'A New Bored';
229
        $desc = 'A purposeful typo';
230
        $newBoard = PulseBoard::createBoard($name, self::MainUser, $desc);
231
232
        $this->assertEquals(self::MainUser, $newBoard->getSubscribers()[0]->getId());
233
        $this->assertEquals($name, $newBoard->getName());
234
        $this->assertEquals($desc, $newBoard->getDescription());
235
    }
236
237
    public function testBoardDeletionMarksObjectAsDeleted()
238
    {
239
        $this->setExpectedException(InvalidObjectException::class);
240
241
        $board = new PulseBoard(27790765, true);
242
        $board->archiveBoard();
243
        $board->archiveBoard();
244
    }
245
246
    public function testBoardGetAll()
247
    {
248
        $boards = PulseBoard::getBoards();
249
250
        $this->assertCount(4, $boards);
251
        $this->assertInstanceOf(PulseBoard::class, $boards[0]);
252
    }
253
}
254