Passed
Push — develop ( 3028c6...9b44cf )
by Mark
29:23
created

DateTimeTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\DateTime;
6
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7
use PhpOffice\PhpSpreadsheet\Shared\Date;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Class DateTimeTest.
12
 */
13
class DateTimeTest extends TestCase
14
{
15
    public function setUp()
16
    {
17
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
18
    }
19
20
    /**
21
     * @dataProvider providerDATE
22
     *
23
     * @param mixed $expectedResult
24
     */
25
    public function testDATE($expectedResult, ...$args)
26
    {
27
        $result = DateTime::DATE(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $year of PhpOffice\PhpSpreadsheet...lation\DateTime::DATE() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        $result = DateTime::DATE(/** @scrutinizer ignore-type */ ...$args);
Loading history...
28
        self::assertEquals($expectedResult, $result, null, 1E-8);
29
    }
30
31
    public function providerDATE()
32
    {
33
        return require 'data/Calculation/DateTime/DATE.php';
34
    }
35
36
    public function testDATEtoPHP()
37
    {
38
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
39
        $result = DateTime::DATE(2012, 1, 31);
40
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
41
        self::assertEquals(1327968000, $result, null, 1E-8);
42
    }
43
44
    public function testDATEtoPHPObject()
45
    {
46
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
47
        $result = DateTime::DATE(2012, 1, 31);
48
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
49
        //    Must return an object...
50
        self::assertInternalType('object', $result);
51
        //    ... of the correct type
52
        self::assertTrue(is_a($result, 'DateTime'));
53
        //    ... with the correct value
54
        self::assertEquals($result->format('d-M-Y'), '31-Jan-2012');
55
    }
56
57
    public function testDATEwith1904Calendar()
58
    {
59
        Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
60
        $result = DateTime::DATE(1918, 11, 11);
61
        Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
62
        self::assertEquals($result, 5428);
63
    }
64
65
    public function testDATEwith1904CalendarError()
66
    {
67
        Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
68
        $result = DateTime::DATE(1901, 1, 31);
69
        Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
70
        self::assertEquals($result, '#NUM!');
71
    }
72
73
    /**
74
     * @dataProvider providerDATEVALUE
75
     *
76
     * @param mixed $expectedResult
77
     */
78
    public function testDATEVALUE($expectedResult, ...$args)
79
    {
80
        $result = DateTime::DATEVALUE(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...n\DateTime::DATEVALUE() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

80
        $result = DateTime::DATEVALUE(/** @scrutinizer ignore-type */ ...$args);
Loading history...
81
        self::assertEquals($expectedResult, $result, null, 1E-8);
82
    }
83
84
    public function providerDATEVALUE()
85
    {
86
        return require 'data/Calculation/DateTime/DATEVALUE.php';
87
    }
88
89
    public function testDATEVALUEtoPHP()
90
    {
91
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
92
        $result = DateTime::DATEVALUE('2012-1-31');
93
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
94
        self::assertEquals(1327968000, $result, null, 1E-8);
95
    }
96
97
    public function testDATEVALUEtoPHPObject()
98
    {
99
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
100
        $result = DateTime::DATEVALUE('2012-1-31');
101
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
102
        //    Must return an object...
103
        self::assertInternalType('object', $result);
104
        //    ... of the correct type
105
        self::assertTrue(is_a($result, 'DateTime'));
106
        //    ... with the correct value
107
        self::assertEquals($result->format('d-M-Y'), '31-Jan-2012');
108
    }
109
110
    /**
111
     * @dataProvider providerYEAR
112
     *
113
     * @param mixed $expectedResult
114
     */
115
    public function testYEAR($expectedResult, ...$args)
116
    {
117
        $result = DateTime::YEAR(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...lation\DateTime::YEAR() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

117
        $result = DateTime::YEAR(/** @scrutinizer ignore-type */ ...$args);
Loading history...
118
        self::assertEquals($expectedResult, $result, null, 1E-8);
119
    }
120
121
    public function providerYEAR()
122
    {
123
        return require 'data/Calculation/DateTime/YEAR.php';
124
    }
125
126
    /**
127
     * @dataProvider providerMONTH
128
     *
129
     * @param mixed $expectedResult
130
     */
131
    public function testMONTH($expectedResult, ...$args)
132
    {
133
        $result = DateTime::MONTHOFYEAR(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...DateTime::MONTHOFYEAR() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

133
        $result = DateTime::MONTHOFYEAR(/** @scrutinizer ignore-type */ ...$args);
Loading history...
134
        self::assertEquals($expectedResult, $result, null, 1E-8);
135
    }
136
137
    public function providerMONTH()
138
    {
139
        return require 'data/Calculation/DateTime/MONTH.php';
140
    }
141
142
    /**
143
     * @dataProvider providerWEEKNUM
144
     *
145
     * @param mixed $expectedResult
146
     */
147
    public function testWEEKNUM($expectedResult, ...$args)
148
    {
149
        $result = DateTime::WEEKNUM(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...ion\DateTime::WEEKNUM() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

149
        $result = DateTime::WEEKNUM(/** @scrutinizer ignore-type */ ...$args);
Loading history...
150
        self::assertEquals($expectedResult, $result, null, 1E-8);
151
    }
152
153
    public function providerWEEKNUM()
154
    {
155
        return require 'data/Calculation/DateTime/WEEKNUM.php';
156
    }
157
158
    /**
159
     * @dataProvider providerISOWEEKNUM
160
     *
161
     * @param mixed $expectedResult
162
     * @param mixed $dateValue
163
     */
164
    public function testISOWEEKNUM($expectedResult, $dateValue)
165
    {
166
        $result = DateTime::ISOWEEKNUM($dateValue);
167
        self::assertEquals($expectedResult, $result, null, 1E-8);
168
    }
169
170
    public function providerISOWEEKNUM()
171
    {
172
        return require 'data/Calculation/DateTime/ISOWEEKNUM.php';
173
    }
174
175
    /**
176
     * @dataProvider providerWEEKDAY
177
     *
178
     * @param mixed $expectedResult
179
     */
180
    public function testWEEKDAY($expectedResult, ...$args)
181
    {
182
        $result = DateTime::WEEKDAY(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...ion\DateTime::WEEKDAY() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

182
        $result = DateTime::WEEKDAY(/** @scrutinizer ignore-type */ ...$args);
Loading history...
183
        self::assertEquals($expectedResult, $result, null, 1E-8);
184
    }
185
186
    public function providerWEEKDAY()
187
    {
188
        return require 'data/Calculation/DateTime/WEEKDAY.php';
189
    }
190
191
    /**
192
     * @dataProvider providerDAY
193
     *
194
     * @param mixed $expectedResultExcel
195
     * @param mixed $expectedResultOpenOffice
196
     */
197
    public function testDAY($expectedResultExcel, $expectedResultOpenOffice, ...$args)
198
    {
199
        $resultExcel = DateTime::DAYOFMONTH(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...\DateTime::DAYOFMONTH() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

199
        $resultExcel = DateTime::DAYOFMONTH(/** @scrutinizer ignore-type */ ...$args);
Loading history...
200
        self::assertEquals($expectedResultExcel, $resultExcel, null, 1E-8);
201
202
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
203
        $resultOpenOffice = DateTime::DAYOFMONTH(...$args);
204
        self::assertEquals($expectedResultOpenOffice, $resultOpenOffice, null, 1E-8);
205
    }
206
207
    public function providerDAY()
208
    {
209
        return require 'data/Calculation/DateTime/DAY.php';
210
    }
211
212
    /**
213
     * @dataProvider providerTIME
214
     *
215
     * @param mixed $expectedResult
216
     */
217
    public function testTIME($expectedResult, ...$args)
218
    {
219
        $result = DateTime::TIME(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $hour of PhpOffice\PhpSpreadsheet...lation\DateTime::TIME() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

219
        $result = DateTime::TIME(/** @scrutinizer ignore-type */ ...$args);
Loading history...
220
        self::assertEquals($expectedResult, $result, null, 1E-8);
221
    }
222
223
    public function providerTIME()
224
    {
225
        return require 'data/Calculation/DateTime/TIME.php';
226
    }
227
228
    public function testTIMEtoPHP()
229
    {
230
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
231
        $result = DateTime::TIME(7, 30, 20);
232
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
233
        self::assertEquals(27020, $result, null, 1E-8);
234
    }
235
236
    public function testTIMEtoPHPObject()
237
    {
238
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
239
        $result = DateTime::TIME(7, 30, 20);
240
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
241
        //    Must return an object...
242
        self::assertInternalType('object', $result);
243
        //    ... of the correct type
244
        self::assertTrue(is_a($result, 'DateTime'));
245
        //    ... with the correct value
246
        self::assertEquals($result->format('H:i:s'), '07:30:20');
247
    }
248
249
    /**
250
     * @dataProvider providerTIMEVALUE
251
     *
252
     * @param mixed $expectedResult
253
     */
254
    public function testTIMEVALUE($expectedResult, ...$args)
255
    {
256
        $result = DateTime::TIMEVALUE(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $timeValue of PhpOffice\PhpSpreadsheet...n\DateTime::TIMEVALUE() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

256
        $result = DateTime::TIMEVALUE(/** @scrutinizer ignore-type */ ...$args);
Loading history...
257
        self::assertEquals($expectedResult, $result, null, 1E-8);
258
    }
259
260
    public function providerTIMEVALUE()
261
    {
262
        return require 'data/Calculation/DateTime/TIMEVALUE.php';
263
    }
264
265
    public function testTIMEVALUEtoPHP()
266
    {
267
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
268
        $result = DateTime::TIMEVALUE('7:30:20');
269
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
270
        self::assertEquals(23420, $result, null, 1E-8);
271
    }
272
273
    public function testTIMEVALUEtoPHPObject()
274
    {
275
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
276
        $result = DateTime::TIMEVALUE('7:30:20');
277
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
278
        //    Must return an object...
279
        self::assertInternalType('object', $result);
280
        //    ... of the correct type
281
        self::assertTrue(is_a($result, 'DateTime'));
282
        //    ... with the correct value
283
        self::assertEquals($result->format('H:i:s'), '07:30:20');
284
    }
285
286
    /**
287
     * @dataProvider providerHOUR
288
     *
289
     * @param mixed $expectedResult
290
     */
291
    public function testHOUR($expectedResult, ...$args)
292
    {
293
        $result = DateTime::HOUROFDAY(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $timeValue of PhpOffice\PhpSpreadsheet...n\DateTime::HOUROFDAY() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

293
        $result = DateTime::HOUROFDAY(/** @scrutinizer ignore-type */ ...$args);
Loading history...
294
        self::assertEquals($expectedResult, $result, null, 1E-8);
295
    }
296
297
    public function providerHOUR()
298
    {
299
        return require 'data/Calculation/DateTime/HOUR.php';
300
    }
301
302
    /**
303
     * @dataProvider providerMINUTE
304
     *
305
     * @param mixed $expectedResult
306
     */
307
    public function testMINUTE($expectedResult, ...$args)
308
    {
309
        $result = DateTime::MINUTE(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $timeValue of PhpOffice\PhpSpreadsheet...tion\DateTime::MINUTE() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

309
        $result = DateTime::MINUTE(/** @scrutinizer ignore-type */ ...$args);
Loading history...
310
        self::assertEquals($expectedResult, $result, null, 1E-8);
311
    }
312
313
    public function providerMINUTE()
314
    {
315
        return require 'data/Calculation/DateTime/MINUTE.php';
316
    }
317
318
    /**
319
     * @dataProvider providerSECOND
320
     *
321
     * @param mixed $expectedResult
322
     */
323
    public function testSECOND($expectedResult, ...$args)
324
    {
325
        $result = DateTime::SECOND(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $timeValue of PhpOffice\PhpSpreadsheet...tion\DateTime::SECOND() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

325
        $result = DateTime::SECOND(/** @scrutinizer ignore-type */ ...$args);
Loading history...
326
        self::assertEquals($expectedResult, $result, null, 1E-8);
327
    }
328
329
    public function providerSECOND()
330
    {
331
        return require 'data/Calculation/DateTime/SECOND.php';
332
    }
333
334
    /**
335
     * @dataProvider providerNETWORKDAYS
336
     *
337
     * @param mixed $expectedResult
338
     */
339
    public function testNETWORKDAYS($expectedResult, ...$args)
340
    {
341
        $result = DateTime::NETWORKDAYS(...$args);
342
        self::assertEquals($expectedResult, $result, null, 1E-8);
343
    }
344
345
    public function providerNETWORKDAYS()
346
    {
347
        return require 'data/Calculation/DateTime/NETWORKDAYS.php';
348
    }
349
350
    /**
351
     * @dataProvider providerWORKDAY
352
     *
353
     * @param mixed $expectedResult
354
     */
355
    public function testWORKDAY($expectedResult, ...$args)
356
    {
357
        $result = DateTime::WORKDAY(...$args);
358
        self::assertEquals($expectedResult, $result, null, 1E-8);
359
    }
360
361
    public function providerWORKDAY()
362
    {
363
        return require 'data/Calculation/DateTime/WORKDAY.php';
364
    }
365
366
    /**
367
     * @dataProvider providerEDATE
368
     *
369
     * @param mixed $expectedResult
370
     */
371
    public function testEDATE($expectedResult, ...$args)
372
    {
373
        $result = DateTime::EDATE(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...ation\DateTime::EDATE() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

373
        $result = DateTime::EDATE(/** @scrutinizer ignore-type */ ...$args);
Loading history...
374
        self::assertEquals($expectedResult, $result, null, 1E-8);
375
    }
376
377
    public function providerEDATE()
378
    {
379
        return require 'data/Calculation/DateTime/EDATE.php';
380
    }
381
382
    public function testEDATEtoPHP()
383
    {
384
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
385
        $result = DateTime::EDATE('2012-1-26', -1);
386
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
387
        self::assertEquals(1324857600, $result, null, 1E-8);
388
    }
389
390
    public function testEDATEtoPHPObject()
391
    {
392
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
393
        $result = DateTime::EDATE('2012-1-26', -1);
394
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
395
        //    Must return an object...
396
        self::assertInternalType('object', $result);
397
        //    ... of the correct type
398
        self::assertTrue(is_a($result, 'DateTime'));
399
        //    ... with the correct value
400
        self::assertEquals($result->format('d-M-Y'), '26-Dec-2011');
401
    }
402
403
    /**
404
     * @dataProvider providerEOMONTH
405
     *
406
     * @param mixed $expectedResult
407
     */
408
    public function testEOMONTH($expectedResult, ...$args)
409
    {
410
        $result = DateTime::EOMONTH(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...ion\DateTime::EOMONTH() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

410
        $result = DateTime::EOMONTH(/** @scrutinizer ignore-type */ ...$args);
Loading history...
411
        self::assertEquals($expectedResult, $result, null, 1E-8);
412
    }
413
414
    public function providerEOMONTH()
415
    {
416
        return require 'data/Calculation/DateTime/EOMONTH.php';
417
    }
418
419
    public function testEOMONTHtoPHP()
420
    {
421
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
422
        $result = DateTime::EOMONTH('2012-1-26', -1);
423
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
424
        self::assertEquals(1325289600, $result, null, 1E-8);
425
    }
426
427
    public function testEOMONTHtoPHPObject()
428
    {
429
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
430
        $result = DateTime::EOMONTH('2012-1-26', -1);
431
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
432
        //    Must return an object...
433
        self::assertInternalType('object', $result);
434
        //    ... of the correct type
435
        self::assertTrue(is_a($result, 'DateTime'));
436
        //    ... with the correct value
437
        self::assertEquals($result->format('d-M-Y'), '31-Dec-2011');
438
    }
439
440
    /**
441
     * @dataProvider providerDATEDIF
442
     *
443
     * @param mixed $expectedResult
444
     */
445
    public function testDATEDIF($expectedResult, ...$args)
446
    {
447
        $result = DateTime::DATEDIF(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $startDate of PhpOffice\PhpSpreadsheet...ion\DateTime::DATEDIF() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

447
        $result = DateTime::DATEDIF(/** @scrutinizer ignore-type */ ...$args);
Loading history...
448
        self::assertEquals($expectedResult, $result, null, 1E-8);
449
    }
450
451
    public function providerDATEDIF()
452
    {
453
        return require 'data/Calculation/DateTime/DATEDIF.php';
454
    }
455
456
    /**
457
     * @dataProvider providerDAYS360
458
     *
459
     * @param mixed $expectedResult
460
     */
461
    public function testDAYS360($expectedResult, ...$args)
462
    {
463
        $result = DateTime::DAYS360(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $startDate of PhpOffice\PhpSpreadsheet...ion\DateTime::DAYS360() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

463
        $result = DateTime::DAYS360(/** @scrutinizer ignore-type */ ...$args);
Loading history...
464
        self::assertEquals($expectedResult, $result, null, 1E-8);
465
    }
466
467
    public function providerDAYS360()
468
    {
469
        return require 'data/Calculation/DateTime/DAYS360.php';
470
    }
471
472
    /**
473
     * @dataProvider providerYEARFRAC
474
     *
475
     * @param mixed $expectedResult
476
     */
477
    public function testYEARFRAC($expectedResult, ...$args)
478
    {
479
        $result = DateTime::YEARFRAC(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $startDate of PhpOffice\PhpSpreadsheet...on\DateTime::YEARFRAC() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

479
        $result = DateTime::YEARFRAC(/** @scrutinizer ignore-type */ ...$args);
Loading history...
480
        self::assertEquals($expectedResult, $result, null, 1E-8);
481
    }
482
483
    public function providerYEARFRAC()
484
    {
485
        return require 'data/Calculation/DateTime/YEARFRAC.php';
486
    }
487
}
488