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

PulseColumnGettersTestCase   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 150
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 2
dl 30
loc 150
rs 10
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 10 1
A testGetNameColumnValues() 15 15 2
A testGetTextColumnValues() 15 15 2
A testGetPersonColumnValues() 0 6 1
A testGetPersonNullColumn() 0 4 1
A testGetDateNullColumn() 0 4 1
A testGetDateColumnValues() 0 12 1
A testGetStatusColumnValues() 0 15 2
A testGetNumericColumnValue() 0 5 1
A testGetNumericColumnNullValue() 0 4 1
A testGetTimelineColumnValue() 0 7 1
A testGetTimelineColumnNullValue() 0 4 1
A testGetBadColumnType() 0 6 1
A testGetNonExistentColumn() 0 6 1
A testGetWrongColumnType() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace allejo\DaPulse\Tests;
4
5
use allejo\DaPulse\Objects\PulseColumnStatusValue;
6
use allejo\DaPulse\Objects\PulseColumnValue;
7
use allejo\DaPulse\Pulse;
8
use allejo\DaPulse\PulseBoard;
9
use allejo\DaPulse\PulseUser;
10
11
class PulseColumnGettersTestCase extends PulseUnitTestCase
12
{
13
    private $id;
14
15
    private $userId;
16
17
    /**
18
     * @var PulseBoard
19
     */
20
    private $board;
21
22
    /**
23
     * @var Pulse[]
24
     */
25
    private $pulses;
26
27
    public function setUp()
28
    {
29
        parent::setUp();
30
31
        $this->id = self::BoardId; // Board ID
32
        $this->userId = self::MainUser; // Main User Account
33
34
        $this->board = new PulseBoard($this->id);
35
        $this->pulses = $this->board->getPulses();
36
    }
37
38 View Code Duplication
    public function testGetNameColumnValues()
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...
39
    {
40
        $expectedValues = array(
41
            "Mock Pulse One",
42
            "Mock Pulse Two",
43
            "Mockery Onion",
44
            "Jar of Jam"
45
        );
46
        $count = count($expectedValues);
47
48
        for ($i = 0; $i < $count; $i++)
49
        {
50
            $this->assertEquals($expectedValues[$i], $this->pulses[$i]->getName());
51
        }
52
    }
53
54 View Code Duplication
    public function testGetTextColumnValues()
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...
55
    {
56
        $expectedValues = array(
57
            "Silver Pet Rock",
58
            "Oblivious Platypus",
59
            "Aspiring Platinum Duck",
60
            null
61
        );
62
        $count = count($expectedValues);
63
64
        for ($i = 0; $i < $count; $i++)
65
        {
66
            $this->assertEquals($expectedValues[$i], $this->pulses[$i]->getTextColumn('text')->getValue());
67
        }
68
    }
69
70
    public function testGetPersonColumnValues()
71
    {
72
        $user = new PulseUser($this->userId);
73
74
        $this->assertEquals($user, $this->pulses[0]->getPersonColumn('person')->getValue());
75
    }
76
77
    public function testGetPersonNullColumn()
78
    {
79
        $this->assertNull($this->pulses[1]->getPersonColumn('person')->getValue());
80
    }
81
82
    public function testGetDateNullColumn()
83
    {
84
        $this->assertNull($this->pulses[2]->getDateColumn('due_date')->getValue());
85
    }
86
87
    public function testGetDateColumnValues()
88
    {
89
        $date = array(
90
            new \DateTime("2017-01-03"),
91
            new \DateTime("2016-10-31"),
92
            null
93
        );
94
95
        $this->assertEquals($date[0], $this->pulses[0]->getDateColumn('due_date')->getValue());
96
        $this->assertEquals($date[1], $this->pulses[1]->getDateColumn('due_date')->getValue());
97
        $this->assertEquals($date[2], $this->pulses[2]->getDateColumn('due_date')->getValue());
98
    }
99
100
    public function testGetStatusColumnValues()
101
    {
102
        $expectedValues = array(
103
            PulseColumnStatusValue::Orange,
104
            PulseColumnStatusValue::Red,
105
            PulseColumnStatusValue::L_Green,
106
            PulseColumnStatusValue::Grey
107
        );
108
        $count = count($expectedValues);
109
110
        for ($i = 0; $i < $count; $i++)
111
        {
112
            $this->assertEquals($expectedValues[$i], $this->pulses[$i]->getStatusColumn('status')->getValue());
113
        }
114
    }
115
116
    public function testGetNumericColumnValue()
117
    {
118
        $this->assertEquals(100.5, $this->pulses[0]->getNumericColumn('numbers')->getValue());
119
        $this->assertEquals(50, $this->pulses[1]->getNumericColumn('numbers')->getValue());
120
    }
121
122
    public function testGetNumericColumnNullValue()
123
    {
124
        $this->assertNull($this->pulses[2]->getNumericColumn('numbers')->getValue());
125
    }
126
127
    public function testGetTimelineColumnValue()
128
    {
129
        $this->assertEquals([
130
            'from' => new \DateTime('2017-01-09'),
131
            'to'   => new \DateTime('2017-01-15')
132
        ], $this->pulses[0]->getTimelineColumn('timeline')->getValue());
133
    }
134
135
    public function testGetTimelineColumnNullValue()
136
    {
137
        $this->assertNull($this->pulses[1]->getTimelineColumn('timeline')->getValue());
138
    }
139
140
    public function testGetBadColumnType()
141
    {
142
        $this->setExpectedException('allejo\DaPulse\Exceptions\InvalidObjectException');
143
144
        PulseColumnValue::_createColumnType("non-existent", array());
145
    }
146
147
    public function testGetNonExistentColumn()
148
    {
149
        $this->setExpectedException('allejo\DaPulse\Exceptions\ColumnNotFoundException');
150
151
        $this->pulses[1]->getDateColumn("non-existent")->getValue();
152
    }
153
154
    public function testGetWrongColumnType()
155
    {
156
        $this->setExpectedException('allejo\DaPulse\Exceptions\InvalidColumnException');
157
158
        $this->pulses[1]->getDateColumn('person')->getValue();
159
    }
160
}
161