1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace common\tests\unit\components; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use common\components\Graph; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Graph test |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
class GraphTest extends \Codeception\Test\Unit |
13
|
|
|
{ |
14
|
|
|
use \Codeception\Specify; |
15
|
|
|
|
16
|
|
|
private $user; |
17
|
|
|
private $filepath = __DIR__.'/../../_output/test_graph.png'; |
18
|
|
|
private $filepath_extra = __DIR__.'/../../_output/charts/test_graph.png'; |
19
|
|
|
|
20
|
|
|
public function setUp() { |
21
|
|
|
$this->user = $this->getMockBuilder('\site\tests\_support\MockUser') |
22
|
|
|
->setMethods(['getIdHash']) |
23
|
|
|
->getMock(); |
24
|
|
|
|
25
|
|
|
parent::setUp(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function tearDown() { |
29
|
|
|
$this->user = null; |
30
|
|
|
parent::tearDown(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testGetFilepath() { |
34
|
|
|
$this->user |
35
|
|
|
->method('getIdHash') |
36
|
|
|
->willReturn('random1DH4sh'); |
37
|
|
|
$graph = new Graph($this->user); |
38
|
|
|
|
39
|
|
|
expect('the expected graph image filepath will be returned', $this->assertEquals(dirname(dirname(dirname(dirname(__DIR__)))).'/site/web/charts/random1DH4sh.png', $graph->getFilepath())); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testGetUrl() { |
43
|
|
|
$this->user |
44
|
|
|
->method('getIdHash') |
45
|
|
|
->willReturn('random1DH4sh'); |
46
|
|
|
$graph = new Graph($this->user); |
47
|
|
|
|
48
|
|
|
expect('the expected graph image filepath will be returned', $this->assertStringEndsWith('/charts/random1DH4sh.png', $graph->getUrl())); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testDestroy() { |
52
|
|
|
$this->graph = $this->getMockBuilder('\common\components\Graph', [$this->user]) |
|
|
|
|
53
|
|
|
->setConstructorArgs([$this->user]) |
54
|
|
|
->setMethods(['getFilepath']) |
55
|
|
|
->getMock(); |
56
|
|
|
$this->graph |
57
|
|
|
->method('getFilepath') |
58
|
|
|
->willReturn($this->filepath); |
59
|
|
|
|
60
|
|
|
if(!file_exists($this->filepath) && preg_match('%/_output/test_graph.png$%', $this->filepath)) { |
61
|
|
|
touch($this->filepath); |
62
|
|
|
expect('just a check to be sure $filepath is sane', $this->assertStringEndsWith('/_output/test_graph.png', $this->filepath)); |
|
|
|
|
63
|
|
|
expect('the generated file should exist', $this->assertFileExists($this->filepath)); |
|
|
|
|
64
|
|
|
expect('the generated file should be readable', $this->assertFileExists($this->filepath)); |
|
|
|
|
65
|
|
|
$this->graph->destroy(); |
66
|
|
|
expect('the generated file should no longer exist', $this->assertFileNotExists($this->filepath)); |
|
|
|
|
67
|
|
|
} else { |
68
|
|
|
expect('the file should not exist yet. If this fails, delete the file', $this->assertFileNotExists($this->filepath)); |
|
|
|
|
69
|
|
|
expect('this should NOT happen', $this->assertTrue(false)); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testCreate() { |
74
|
|
|
$this->graph = $this->getMockBuilder('\common\components\Graph', [$this->user]) |
|
|
|
|
75
|
|
|
->setConstructorArgs([$this->user]) |
76
|
|
|
->setMethods(['getFilepath']) |
77
|
|
|
->getMock(); |
78
|
|
|
$this->graph |
79
|
|
|
->method('getFilepath') |
80
|
|
|
->willReturn($this->filepath_extra); |
81
|
|
|
|
82
|
|
|
expect('the file should not exist yet. If this fails, delete the file', $this->assertFileNotExists($this->filepath)); |
|
|
|
|
83
|
|
|
expect('the containing directory should not exist yet either. If this fails, delete the directory', $this->assertFalse(is_dir(dirname($this->filepath_extra)))); |
|
|
|
|
84
|
|
|
|
85
|
|
|
$this->graph->create(checkinBreakdown(), true); |
86
|
|
|
|
87
|
|
|
expect('just a check to be sure $filepath_extra is sane', $this->assertStringEndsWith('/_output/charts/test_graph.png', $this->filepath_extra)); |
|
|
|
|
88
|
|
|
expect('the generated file should exist', $this->assertFileExists($this->filepath_extra)); |
|
|
|
|
89
|
|
|
expect('the generated file should be readable', $this->assertFileExists($this->filepath_extra)); |
|
|
|
|
90
|
|
|
|
91
|
|
|
// cleanup |
92
|
|
|
if(file_exists($this->filepath_extra) && preg_match('%/_output/charts/test_graph.png%', $this->filepath_extra)) { |
93
|
|
|
// just in case something is weird, we don't want to straight rm this file |
94
|
|
|
unlink($this->filepath_extra); |
95
|
|
|
rmdir(dirname($this->filepath_extra)); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
function checkinBreakdown () { |
101
|
|
|
return [ |
102
|
|
|
'2019-01-31' => [], |
103
|
|
|
'2019-02-01' => [], |
104
|
|
|
'2019-02-02' => [ |
105
|
|
|
1 => [ |
106
|
|
|
'name' => 'Restoration', |
107
|
|
|
'count' => 4, |
108
|
|
|
'color' => '#008000', |
109
|
|
|
'highlight' => '#199919', |
110
|
|
|
], 2 => [ |
111
|
|
|
'name' => 'Forgetting Priorities', |
112
|
|
|
'count' => 4, |
113
|
|
|
'color' => '#4CA100', |
114
|
|
|
'highlight' => '#61B219', |
115
|
|
|
], 3 => [ |
116
|
|
|
'name' => 'Anxiety', |
117
|
|
|
'count' => 7, |
118
|
|
|
'color' => '#98C300', |
119
|
|
|
'highlight' => '#AACC33', |
120
|
|
|
], 4 => [ |
121
|
|
|
'name' => 'Speeding Up', |
122
|
|
|
'count' => 5, |
123
|
|
|
'color' => '#E5E500', |
124
|
|
|
'highlight' => '#E5E533', |
125
|
|
|
], 5 => [ |
126
|
|
|
'name' => 'Ticked Off', |
127
|
|
|
'count' => 5, |
128
|
|
|
'color' => '#E59900', |
129
|
|
|
'highlight' => '#E5AA33', |
130
|
|
|
], 6 => [ |
131
|
|
|
'name' => 'Exhausted', |
132
|
|
|
'count' => 5, |
133
|
|
|
'color' => '#E54B00', |
134
|
|
|
'highlight' => '#E56D33', |
135
|
|
|
], 7 => [ |
136
|
|
|
'name' => 'Relapse/Moral Failure', |
137
|
|
|
'count' => 3, |
138
|
|
|
'color' => '#CC0000', |
139
|
|
|
'highlight' => '#CC3333', |
140
|
|
|
], |
141
|
|
|
], |
142
|
|
|
'2019-02-03' => [], |
143
|
|
|
'2019-02-04' => [ |
144
|
|
|
1 => [ |
145
|
|
|
'name' => 'Restoration', |
146
|
|
|
'count' => 3, |
147
|
|
|
'color' => '#008000', |
148
|
|
|
'highlight' => '#199919', |
149
|
|
|
], 2 => [ |
150
|
|
|
'name' => 'Forgetting Priorities', |
151
|
|
|
'count' => 5, |
152
|
|
|
'color' => '#4CA100', |
153
|
|
|
'highlight' => '#61B219', |
154
|
|
|
], 3 => [ |
155
|
|
|
'name' => 'Anxiety', |
156
|
|
|
'count' => 3, |
157
|
|
|
'color' => '#98C300', |
158
|
|
|
'highlight' => '#AACC33', |
159
|
|
|
], 4 => [ |
160
|
|
|
'name' => 'Speeding Up', |
161
|
|
|
'count' => 1, |
162
|
|
|
'color' => '#E5E500', |
163
|
|
|
'highlight' => '#E5E533', |
164
|
|
|
], 5 => [ |
165
|
|
|
'name' => 'Ticked Off', |
166
|
|
|
'count' => 3, |
167
|
|
|
'color' => '#E59900', |
168
|
|
|
'highlight' => '#E5AA33', |
169
|
|
|
], 6 => [ |
170
|
|
|
'name' => 'Exhausted', |
171
|
|
|
'count' => 7, |
172
|
|
|
'color' => '#E54B00', |
173
|
|
|
'highlight' => '#E56D33', |
174
|
|
|
], |
175
|
|
|
], |
176
|
|
|
'2019-02-05' => [], |
177
|
|
|
'2019-02-06' => [], |
178
|
|
|
'2019-02-07' => [], |
179
|
|
|
'2019-02-08' => [], |
180
|
|
|
'2019-02-09' => [ |
181
|
|
|
2 => [ |
182
|
|
|
'name' => 'Forgetting Priorities', |
183
|
|
|
'count' => 6, |
184
|
|
|
'color' => '#4CA100', |
185
|
|
|
'highlight' => '#61B219', |
186
|
|
|
], 3 => [ |
187
|
|
|
'name' => 'Anxiety', |
188
|
|
|
'count' => 3, |
189
|
|
|
'color' => '#98C300', |
190
|
|
|
'highlight' => '#AACC33', |
191
|
|
|
], 4 => [ |
192
|
|
|
'name' => 'Speeding Up', |
193
|
|
|
'count' => 4, |
194
|
|
|
'color' => '#E5E500', |
195
|
|
|
'highlight' => '#E5E533', |
196
|
|
|
], 5 => [ |
197
|
|
|
'name' => 'Ticked Off', |
198
|
|
|
'count' => 8, |
199
|
|
|
'color' => '#E59900', |
200
|
|
|
'highlight' => '#E5AA33', |
201
|
|
|
], 6 => [ |
202
|
|
|
'name' => 'Exhausted', |
203
|
|
|
'count' => 6, |
204
|
|
|
'color' => '#E54B00', |
205
|
|
|
'highlight' => '#E56D33', |
206
|
|
|
], 7 => [ |
207
|
|
|
'name' => 'Relapse/Moral Failure', |
208
|
|
|
'count' => 7, |
209
|
|
|
'color' => '#CC0000', |
210
|
|
|
'highlight' => '#CC3333', |
211
|
|
|
], |
212
|
|
|
], |
213
|
|
|
'2019-02-10' => [], |
214
|
|
|
'2019-02-11' => [], |
215
|
|
|
'2019-02-12' => [], |
216
|
|
|
'2019-02-13' => [], |
217
|
|
|
'2019-02-14' => [], |
218
|
|
|
'2019-02-15' => [], |
219
|
|
|
'2019-02-16' => [], |
220
|
|
|
'2019-02-17' => [], |
221
|
|
|
'2019-02-18' => [], |
222
|
|
|
'2019-02-19' => [], |
223
|
|
|
'2019-02-20' => [], |
224
|
|
|
'2019-02-21' => [], |
225
|
|
|
'2019-02-22' => [], |
226
|
|
|
'2019-02-23' => [], |
227
|
|
|
'2019-02-24' => [], |
228
|
|
|
'2019-02-25' => [], |
229
|
|
|
'2019-02-26' => [], |
230
|
|
|
'2019-02-27' => [], |
231
|
|
|
'2019-02-28' => [], |
232
|
|
|
'2019-03-01' => [ |
233
|
|
|
2 => [ 'name' => 'Forgetting Priorities', |
234
|
|
|
'count' => 6, |
235
|
|
|
'color' => '#4CA100', |
236
|
|
|
'highlight' => '#61B219', |
237
|
|
|
], 3 => [ |
238
|
|
|
'name' => 'Anxiety', |
239
|
|
|
'count' => 5, |
240
|
|
|
'color' => '#98C300', |
241
|
|
|
'highlight' => '#AACC33', |
242
|
|
|
], 4 => [ |
243
|
|
|
'name' => 'Speeding Up', |
244
|
|
|
'count' => 6, |
245
|
|
|
'color' => '#E5E500', |
246
|
|
|
'highlight' => '#E5E533', |
247
|
|
|
], |
248
|
|
|
], |
249
|
|
|
]; |
250
|
|
|
} |
251
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.