Completed
Branch master (cf27fb)
by Vladimir
02:33
created

testSettingNonExistentColumn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace allejo\DaPulse\Tests;
4
5
use allejo\DaPulse\Objects\PulseColumnStatusValue;
6
use allejo\DaPulse\Pulse;
7
use allejo\DaPulse\PulseUser;
8
9
class PulseColumnSettersTestCase extends PulseUnitTestCase
10
{
11
    private $userId;
12
13
    /**
14
     * @var Pulse
15
     */
16
    private $pulse;
17
18
    public static function invalidColorValueProvider()
19
    {
20
        return array(
21
            array(-1),
22
            array(11),
23
            array(9.8),
24
            array('hello world')
25
        );
26
    }
27
28
    public static function invalidTextProvider()
29
    {
30
        return [
31
            [new \stdClass()],
32
            [null]
33
        ];
34
    }
35
36
    public static function invalidNumericProvider()
37
    {
38
        return [
39
            ['hello'],
40
            [true],
41
            [new \stdClass()],
42
            [null]
43
        ];
44
    }
45
46
    public static function invalidDateTimeProvider()
47
    {
48
        return [
49
            [1483228800],
50
            ['2017-01-01'],
51
            [new \stdClass()],
52
            [null]
53
        ];
54
    }
55
56
    public static function invalidPersonProvider()
57
    {
58
        return [
59
            [130.4],
60
            [-1200],
61
            ['qwerty'],
62
            [new \stdClass()],
63
            [null]
64
        ];
65
    }
66
67
    public static function invalidTimelineProvider()
68
    {
69
        return [
70
            [new \DateTime('2017-01-01'), null],
71
            [null, new \DateTime('2017-01-01')]
72
        ];
73
    }
74
75
    public function setUp()
76
    {
77
        parent::setUp();
78
79
        $this->userId = self::MainUser;
80
        $this->pulse = new Pulse(27168882);
81
    }
82
83
    public function testSettingStatusColumn()
84
    {
85
        $value = PulseColumnStatusValue::Gold;
86
        $column = $this->pulse->getStatusColumn('status');
87
        $column->updateValue($value);
88
89
        $this->assertEquals($value, $column->getValue());
90
    }
91
92
    /**
93
     * @dataProvider invalidColorValueProvider
94
     */
95
    public function testSettingStatusColumnWithWrongTypes($color)
96
    {
97
        $this->setExpectedException('\InvalidArgumentException');
98
99
        $this->pulse->getStatusColumn('status')->updateValue($color);
100
    }
101
102 View Code Duplication
    public function testSettingTextColumn()
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...
103
    {
104
        $value = 'Elastic Water Bottle';
105
        $column = $this->pulse->getTextColumn('text');
106
        $column->updateValue($value);
107
108
        $this->assertEquals($value, $column->getValue());
109
    }
110
111
    /**
112
     * @dataProvider invalidTextProvider
113
     */
114
    public function testSettingTextColumnWithWrongTypes($value)
115
    {
116
        $this->setExpectedException(\InvalidArgumentException::class);
117
118
        $this->pulse->getTextColumn('text')->updateValue($value);
119
    }
120
121 View Code Duplication
    public function testSettingNumericColumn()
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...
122
    {
123
        $value = 25;
124
        $column = $this->pulse->getNumericColumn('numbers');
125
        $column->updateValue($value);
126
127
        $this->assertEquals($value, $column->getValue());
128
    }
129
130
    /**
131
     * @dataProvider invalidNumericProvider
132
     */
133
    public function testSettingNumericColumnWithWrongTypes($value)
134
    {
135
        $this->setExpectedException(\InvalidArgumentException::class);
136
137
        $this->pulse->getNumericColumn('numbers')->updateValue($value);
138
    }
139
140
    public function testSettingDateColumn()
141
    {
142
        $value = new \DateTime('2017-02-01');
143
        $column = $this->pulse->getDateColumn('due_date');
144
        $column->updateValue($value);
145
146
        $this->assertEquals($value, $column->getValue());
147
    }
148
149
    /**
150
     * @dataProvider invalidDateTimeProvider
151
     */
152
    public function testSettingDateColumnWithWrongTypes($value)
153
    {
154
        $this->setExpectedException(\InvalidArgumentException::class);
155
156
        $this->pulse->getDateColumn('due_date')->updateValue($value);
157
    }
158
159
    public function testSettingTimelineColumn()
160
    {
161
        $from = new \DateTime('2016-01-01');
162
        $to   = new \DateTime('2016-01-26');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $to. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
163
        $column = $this->pulse->getTimelineColumn('timeline');
164
        $column->updateValue($from, $to);
165
166
        $this->assertEquals(['from' => $from, 'to' => $to], $column->getValue());
167
    }
168
169
    /**
170
     * @dataProvider invalidTimelineProvider
171
     */
172
    public function testSettingTimelineColumnWithWrongTypes($dateOne, $dateTwo)
173
    {
174
        $this->setExpectedException(\InvalidArgumentException::class);
175
176
        $this->pulse->getTimelineColumn('timeline')->updateValue($dateOne, $dateTwo);
177
    }
178
179
    public function testSettingPersonColumnFromInt()
180
    {
181
        $column = $this->pulse->getPersonColumn('person');
182
        $column->updateValue($this->userId);
183
184
        $this->assertEquals($this->userId, $column->getValue()->getId());
185
    }
186
187
    public function testSettingPersonColumnFromObject()
188
    {
189
        $user = new PulseUser($this->userId);
190
        $column = $this->pulse->getPersonColumn('person');
191
        $column->updateValue($user);
192
193
        $this->assertEquals($user, $column->getValue());
194
    }
195
196
    /**
197
     * @dataProvider invalidPersonProvider
198
     */
199
    public function testSettingPersonColumnWithWrongTypes($value)
200
    {
201
        $this->setExpectedException(\InvalidArgumentException::class);
202
203
        $this->pulse->getPersonColumn('person')->updateValue($value);
204
    }
205
206
    public function testSettingNonExistentColumn()
207
    {
208
        $this->markTestIncomplete('I need to get the response from DaPulse to create the mock');
209
210
        $this->setExpectedException('allejo\DaPulse\Exceptions\ColumnNotFoundException');
211
212
        $this->pulse->getTextColumn("non-existent")->updateValue('Hello world');
213
    }
214
}
215