TestOfValidatorLive   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 27
dl 0
loc 70
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A testSecond() 0 5 1
A __construct() 0 3 1
A testMonth() 0 5 1
A testHour() 0 5 1
A testYear() 0 5 1
A testDay() 0 5 1
A testMinute() 0 5 1
A testAllBad() 0 10 2
1
<?php
2
3
require_once __DIR__ . '/simple_include.php';
4
require_once __DIR__ . '/calendar_include.php';
5
6
Mock::generate('Calendar_Engine_Interface', 'Mock_Calendar_Engine');
0 ignored issues
show
Bug introduced by
The type Mock was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
Mock::generate('Calendar_Second', 'Mock_Calendar_Second');
8
9
/**
10
 * Class TestOfValidator.
11
 */
12
class TestOfValidator extends UnitTestCase
0 ignored issues
show
Bug introduced by
The type UnitTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
    public $mockengine;
15
    public $mockcal;
16
17
    /**
18
     * TestOfValidator constructor.
19
     */
20
    public function __construct()
21
    {
22
        parent::__construct('Test of Validator');
23
    }
24
25
    protected function setUp()
26
    {
27
        $this->mockengine = new Mock_Calendar_Engine($this);
0 ignored issues
show
Bug introduced by
The type Mock_Calendar_Engine was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
        $this->mockengine->setReturnValue('getMinYears', 1970);
29
        $this->mockengine->setReturnValue('getMaxYears', 2037);
30
        $this->mockengine->setReturnValue('getMonthsInYear', 12);
31
        $this->mockengine->setReturnValue('getDaysInMonth', 30);
32
        $this->mockengine->setReturnValue('getHoursInDay', 24);
33
        $this->mockengine->setReturnValue('getMinutesInHour', _EXTCAL_TS_MINUTE);
34
        $this->mockengine->setReturnValue('getSecondsInMinute', _EXTCAL_TS_MINUTE);
35
        $this->mockcal = new Mock_Calendar_Second($this);
0 ignored issues
show
Bug introduced by
The type Mock_Calendar_Second was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
        $this->mockcal->setReturnValue('getEngine', $this->mockengine);
37
    }
38
39
    protected function tearDown()
40
    {
41
        unset($this->mockengine, $this->mocksecond);
42
    }
43
44
    public function testIsValidYear()
45
    {
46
        $this->mockcal->setReturnValue('thisYear', 2000);
47
        $Validator = new Calendar_Validator($this->mockcal);
48
        $this->assertTrue($Validator->isValidYear());
49
    }
50
51
    public function testIsValidYearTooSmall()
52
    {
53
        $this->mockcal->setReturnValue('thisYear', 1969);
54
        $Validator = new Calendar_Validator($this->mockcal);
55
        $this->assertFalse($Validator->isValidYear());
56
    }
57
58
    public function testIsValidYearTooLarge()
59
    {
60
        $this->mockcal->setReturnValue('thisYear', 2038);
61
        $Validator = new Calendar_Validator($this->mockcal);
62
        $this->assertFalse($Validator->isValidYear());
63
    }
64
65
    public function testIsValidMonth()
66
    {
67
        $this->mockcal->setReturnValue('thisMonth', 10);
68
        $Validator = new Calendar_Validator($this->mockcal);
69
        $this->assertTrue($Validator->isValidMonth());
70
    }
71
72
    public function testIsValidMonthTooSmall()
73
    {
74
        $this->mockcal->setReturnValue('thisMonth', 0);
75
        $Validator = new Calendar_Validator($this->mockcal);
76
        $this->assertFalse($Validator->isValidMonth());
77
    }
78
79
    public function testIsValidMonthTooLarge()
80
    {
81
        $this->mockcal->setReturnValue('thisMonth', 13);
82
        $Validator = new Calendar_Validator($this->mockcal);
83
        $this->assertFalse($Validator->isValidMonth());
84
    }
85
86
    public function testIsValidDay()
87
    {
88
        $this->mockcal->setReturnValue('thisDay', 10);
89
        $Validator = new Calendar_Validator($this->mockcal);
90
        $this->assertTrue($Validator->isValidDay());
91
    }
92
93
    public function testIsValidDayTooSmall()
94
    {
95
        $this->mockcal->setReturnValue('thisDay', 0);
96
        $Validator = new Calendar_Validator($this->mockcal);
97
        $this->assertFalse($Validator->isValidDay());
98
    }
99
100
    public function testIsValidDayTooLarge()
101
    {
102
        $this->mockcal->setReturnValue('thisDay', 31);
103
        $Validator = new Calendar_Validator($this->mockcal);
104
        $this->assertFalse($Validator->isValidDay());
105
    }
106
107
    public function testIsValidHour()
108
    {
109
        $this->mockcal->setReturnValue('thisHour', 10);
110
        $Validator = new Calendar_Validator($this->mockcal);
111
        $this->assertTrue($Validator->isValidHour());
112
    }
113
114
    public function testIsValidHourTooSmall()
115
    {
116
        $this->mockcal->setReturnValue('thisHour', -1);
117
        $Validator = new Calendar_Validator($this->mockcal);
118
        $this->assertFalse($Validator->isValidHour());
119
    }
120
121
    public function testIsValidHourTooLarge()
122
    {
123
        $this->mockcal->setReturnValue('thisHour', 24);
124
        $Validator = new Calendar_Validator($this->mockcal);
125
        $this->assertFalse($Validator->isValidHour());
126
    }
127
128
    public function testIsValidMinute()
129
    {
130
        $this->mockcal->setReturnValue('thisMinute', 30);
131
        $Validator = new Calendar_Validator($this->mockcal);
132
        $this->assertTrue($Validator->isValidMinute());
133
    }
134
135
    public function testIsValidMinuteTooSmall()
136
    {
137
        $this->mockcal->setReturnValue('thisMinute', -1);
138
        $Validator = new Calendar_Validator($this->mockcal);
139
        $this->assertFalse($Validator->isValidMinute());
140
    }
141
142
    public function testIsValidMinuteTooLarge()
143
    {
144
        $this->mockcal->setReturnValue('thisMinute', _EXTCAL_TS_MINUTE);
145
        $Validator = new Calendar_Validator($this->mockcal);
146
        $this->assertFalse($Validator->isValidMinute());
147
    }
148
149
    public function testIsValidSecond()
150
    {
151
        $this->mockcal->setReturnValue('thisSecond', 30);
152
        $Validator = new Calendar_Validator($this->mockcal);
153
        $this->assertTrue($Validator->isValidSecond());
154
    }
155
156
    public function testIsValidSecondTooSmall()
157
    {
158
        $this->mockcal->setReturnValue('thisSecond', -1);
159
        $Validator = new Calendar_Validator($this->mockcal);
160
        $this->assertFalse($Validator->isValidSecond());
161
    }
162
163
    public function testIsValidSecondTooLarge()
164
    {
165
        $this->mockcal->setReturnValue('thisSecond', _EXTCAL_TS_MINUTE);
166
        $Validator = new Calendar_Validator($this->mockcal);
167
        $this->assertFalse($Validator->isValidSecond());
168
    }
169
170
    public function testIsValid()
171
    {
172
        $this->mockcal->setReturnValue('thisYear', 2000);
173
        $this->mockcal->setReturnValue('thisMonth', 5);
174
        $this->mockcal->setReturnValue('thisDay', 15);
175
        $this->mockcal->setReturnValue('thisHour', 13);
176
        $this->mockcal->setReturnValue('thisMinute', 30);
177
        $this->mockcal->setReturnValue('thisSecond', 40);
178
        $Validator = new Calendar_Validator($this->mockcal);
179
        $this->assertTrue($Validator->isValid());
180
    }
181
182
    public function testIsValidAllWrong()
183
    {
184
        $this->mockcal->setReturnValue('thisYear', 2038);
185
        $this->mockcal->setReturnValue('thisMonth', 13);
186
        $this->mockcal->setReturnValue('thisDay', 31);
187
        $this->mockcal->day = 31;
188
        $this->mockcal->setReturnValue('thisHour', 24);
189
        $this->mockcal->setReturnValue('thisMinute', _EXTCAL_TS_MINUTE);
190
        $this->mockcal->setReturnValue('thisSecond', _EXTCAL_TS_MINUTE);
191
        $Validator = new Calendar_Validator($this->mockcal);
192
        $this->assertFalse($Validator->isValid());
193
        $i = 0;
194
        while ($Validator->fetch()) {
195
            ++$i;
196
        }
197
        $this->assertEqual($i, 6);
198
    }
199
}
200
201
/**
202
 * Class TestOfValidatorLive.
203
 */
204
class TestOfValidatorLive extends UnitTestCase
205
{
206
    /**
207
     * TestOfValidatorLive constructor.
208
     */
209
    public function __construct()
210
    {
211
        parent::__construct('Test of Validator Live');
212
    }
213
214
    public function testYear()
215
    {
216
        $Unit      = new Calendar_Year(2038);
217
        $Validator = $Unit->getValidator();
218
        $this->assertFalse($Validator->isValidYear());
219
    }
220
221
    public function testMonth()
222
    {
223
        $Unit      = new Calendar_Month(2000, 13);
224
        $Validator = $Unit->getValidator();
225
        $this->assertFalse($Validator->isValidMonth());
226
    }
227
228
    /*
229
        function testWeek()
230
        {
231
            $Unit = new Calendar_Week(2000,12,7);
232
            $Validator = $Unit->getValidator();
233
            $this->assertFalse($Validator->isValidWeek());
234
        }
235
    */
236
    public function testDay()
237
    {
238
        $Unit      = new Calendar_Day(2000, 12, 32);
239
        $Validator = $Unit->getValidator();
240
        $this->assertFalse($Validator->isValidDay());
241
    }
242
243
    public function testHour()
244
    {
245
        $Unit      = new Calendar_Hour(2000, 12, 20, 24);
246
        $Validator = $Unit->getValidator();
247
        $this->assertFalse($Validator->isValidHour());
248
    }
249
250
    public function testMinute()
251
    {
252
        $Unit      = new Calendar_Minute(2000, 12, 20, 23, _EXTCAL_TS_MINUTE);
253
        $Validator = $Unit->getValidator();
254
        $this->assertFalse($Validator->isValidMinute());
255
    }
256
257
    public function testSecond()
258
    {
259
        $Unit      = new Calendar_Second(2000, 12, 20, 23, 59, _EXTCAL_TS_MINUTE);
260
        $Validator = $Unit->getValidator();
261
        $this->assertFalse($Validator->isValidSecond());
262
    }
263
264
    public function testAllBad()
265
    {
266
        $Unit = new Calendar_Second(2000, 13, 32, 24, _EXTCAL_TS_MINUTE, _EXTCAL_TS_MINUTE);
267
        $this->assertFalse($Unit->isValid());
268
        $Validator = $Unit->getValidator();
269
        $i         = 0;
270
        while ($Validator->fetch()) {
271
            ++$i;
272
        }
273
        $this->assertEqual($i, 5);
274
    }
275
}
276
277
if (!defined('TEST_RUNNING')) {
278
    define('TEST_RUNNING', true);
279
    $test = new TestOfValidator();
280
    $test->run(new HtmlReporter());
0 ignored issues
show
Bug introduced by
The type HtmlReporter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
281
    $test = new TestOfValidatorLive();
282
    $test->run(new HtmlReporter());
283
}
284