Failed Conditions
Push — develop ( a6bb49...7a4cbd )
by Adrien
36:15
created

DateTimeTest::providerMONTH()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 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 providerWEEKDAY
160
     *
161
     * @param mixed $expectedResult
162
     */
163
    public function testWEEKDAY($expectedResult, ...$args)
164
    {
165
        $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

165
        $result = DateTime::WEEKDAY(/** @scrutinizer ignore-type */ ...$args);
Loading history...
166
        self::assertEquals($expectedResult, $result, null, 1E-8);
167
    }
168
169
    public function providerWEEKDAY()
170
    {
171
        return require 'data/Calculation/DateTime/WEEKDAY.php';
172
    }
173
174
    /**
175
     * @dataProvider providerDAY
176
     *
177
     * @param mixed $expectedResultExcel
178
     * @param mixed $expectedResultOpenOffice
179
     */
180
    public function testDAY($expectedResultExcel, $expectedResultOpenOffice, ...$args)
181
    {
182
        $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

182
        $resultExcel = DateTime::DAYOFMONTH(/** @scrutinizer ignore-type */ ...$args);
Loading history...
183
        self::assertEquals($expectedResultExcel, $resultExcel, null, 1E-8);
184
185
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
186
        $resultOpenOffice = DateTime::DAYOFMONTH(...$args);
187
        self::assertEquals($expectedResultOpenOffice, $resultOpenOffice, null, 1E-8);
188
    }
189
190
    public function providerDAY()
191
    {
192
        return require 'data/Calculation/DateTime/DAY.php';
193
    }
194
195
    /**
196
     * @dataProvider providerTIME
197
     *
198
     * @param mixed $expectedResult
199
     */
200
    public function testTIME($expectedResult, ...$args)
201
    {
202
        $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

202
        $result = DateTime::TIME(/** @scrutinizer ignore-type */ ...$args);
Loading history...
203
        self::assertEquals($expectedResult, $result, null, 1E-8);
204
    }
205
206
    public function providerTIME()
207
    {
208
        return require 'data/Calculation/DateTime/TIME.php';
209
    }
210
211
    public function testTIMEtoPHP()
212
    {
213
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
214
        $result = DateTime::TIME(7, 30, 20);
215
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
216
        self::assertEquals(27020, $result, null, 1E-8);
217
    }
218
219
    public function testTIMEtoPHPObject()
220
    {
221
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
222
        $result = DateTime::TIME(7, 30, 20);
223
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
224
        //    Must return an object...
225
        self::assertInternalType('object', $result);
226
        //    ... of the correct type
227
        self::assertTrue(is_a($result, 'DateTime'));
228
        //    ... with the correct value
229
        self::assertEquals($result->format('H:i:s'), '07:30:20');
230
    }
231
232
    /**
233
     * @dataProvider providerTIMEVALUE
234
     *
235
     * @param mixed $expectedResult
236
     */
237
    public function testTIMEVALUE($expectedResult, ...$args)
238
    {
239
        $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

239
        $result = DateTime::TIMEVALUE(/** @scrutinizer ignore-type */ ...$args);
Loading history...
240
        self::assertEquals($expectedResult, $result, null, 1E-8);
241
    }
242
243
    public function providerTIMEVALUE()
244
    {
245
        return require 'data/Calculation/DateTime/TIMEVALUE.php';
246
    }
247
248
    public function testTIMEVALUEtoPHP()
249
    {
250
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
251
        $result = DateTime::TIMEVALUE('7:30:20');
252
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
253
        self::assertEquals(23420, $result, null, 1E-8);
254
    }
255
256
    public function testTIMEVALUEtoPHPObject()
257
    {
258
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
259
        $result = DateTime::TIMEVALUE('7:30:20');
260
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
261
        //    Must return an object...
262
        self::assertInternalType('object', $result);
263
        //    ... of the correct type
264
        self::assertTrue(is_a($result, 'DateTime'));
265
        //    ... with the correct value
266
        self::assertEquals($result->format('H:i:s'), '07:30:20');
267
    }
268
269
    /**
270
     * @dataProvider providerHOUR
271
     *
272
     * @param mixed $expectedResult
273
     */
274
    public function testHOUR($expectedResult, ...$args)
275
    {
276
        $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

276
        $result = DateTime::HOUROFDAY(/** @scrutinizer ignore-type */ ...$args);
Loading history...
277
        self::assertEquals($expectedResult, $result, null, 1E-8);
278
    }
279
280
    public function providerHOUR()
281
    {
282
        return require 'data/Calculation/DateTime/HOUR.php';
283
    }
284
285
    /**
286
     * @dataProvider providerMINUTE
287
     *
288
     * @param mixed $expectedResult
289
     */
290
    public function testMINUTE($expectedResult, ...$args)
291
    {
292
        $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

292
        $result = DateTime::MINUTE(/** @scrutinizer ignore-type */ ...$args);
Loading history...
293
        self::assertEquals($expectedResult, $result, null, 1E-8);
294
    }
295
296
    public function providerMINUTE()
297
    {
298
        return require 'data/Calculation/DateTime/MINUTE.php';
299
    }
300
301
    /**
302
     * @dataProvider providerSECOND
303
     *
304
     * @param mixed $expectedResult
305
     */
306
    public function testSECOND($expectedResult, ...$args)
307
    {
308
        $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

308
        $result = DateTime::SECOND(/** @scrutinizer ignore-type */ ...$args);
Loading history...
309
        self::assertEquals($expectedResult, $result, null, 1E-8);
310
    }
311
312
    public function providerSECOND()
313
    {
314
        return require 'data/Calculation/DateTime/SECOND.php';
315
    }
316
317
    /**
318
     * @dataProvider providerNETWORKDAYS
319
     *
320
     * @param mixed $expectedResult
321
     */
322
    public function testNETWORKDAYS($expectedResult, ...$args)
323
    {
324
        $result = DateTime::NETWORKDAYS(...$args);
325
        self::assertEquals($expectedResult, $result, null, 1E-8);
326
    }
327
328
    public function providerNETWORKDAYS()
329
    {
330
        return require 'data/Calculation/DateTime/NETWORKDAYS.php';
331
    }
332
333
    /**
334
     * @dataProvider providerWORKDAY
335
     *
336
     * @param mixed $expectedResult
337
     */
338
    public function testWORKDAY($expectedResult, ...$args)
339
    {
340
        $result = DateTime::WORKDAY(...$args);
341
        self::assertEquals($expectedResult, $result, null, 1E-8);
342
    }
343
344
    public function providerWORKDAY()
345
    {
346
        return require 'data/Calculation/DateTime/WORKDAY.php';
347
    }
348
349
    /**
350
     * @dataProvider providerEDATE
351
     *
352
     * @param mixed $expectedResult
353
     */
354
    public function testEDATE($expectedResult, ...$args)
355
    {
356
        $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

356
        $result = DateTime::EDATE(/** @scrutinizer ignore-type */ ...$args);
Loading history...
357
        self::assertEquals($expectedResult, $result, null, 1E-8);
358
    }
359
360
    public function providerEDATE()
361
    {
362
        return require 'data/Calculation/DateTime/EDATE.php';
363
    }
364
365
    public function testEDATEtoPHP()
366
    {
367
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
368
        $result = DateTime::EDATE('2012-1-26', -1);
369
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
370
        self::assertEquals(1324857600, $result, null, 1E-8);
371
    }
372
373
    public function testEDATEtoPHPObject()
374
    {
375
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
376
        $result = DateTime::EDATE('2012-1-26', -1);
377
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
378
        //    Must return an object...
379
        self::assertInternalType('object', $result);
380
        //    ... of the correct type
381
        self::assertTrue(is_a($result, 'DateTime'));
382
        //    ... with the correct value
383
        self::assertEquals($result->format('d-M-Y'), '26-Dec-2011');
384
    }
385
386
    /**
387
     * @dataProvider providerEOMONTH
388
     *
389
     * @param mixed $expectedResult
390
     */
391
    public function testEOMONTH($expectedResult, ...$args)
392
    {
393
        $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

393
        $result = DateTime::EOMONTH(/** @scrutinizer ignore-type */ ...$args);
Loading history...
394
        self::assertEquals($expectedResult, $result, null, 1E-8);
395
    }
396
397
    public function providerEOMONTH()
398
    {
399
        return require 'data/Calculation/DateTime/EOMONTH.php';
400
    }
401
402
    public function testEOMONTHtoPHP()
403
    {
404
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
405
        $result = DateTime::EOMONTH('2012-1-26', -1);
406
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
407
        self::assertEquals(1325289600, $result, null, 1E-8);
408
    }
409
410
    public function testEOMONTHtoPHPObject()
411
    {
412
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
413
        $result = DateTime::EOMONTH('2012-1-26', -1);
414
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
415
        //    Must return an object...
416
        self::assertInternalType('object', $result);
417
        //    ... of the correct type
418
        self::assertTrue(is_a($result, 'DateTime'));
419
        //    ... with the correct value
420
        self::assertEquals($result->format('d-M-Y'), '31-Dec-2011');
421
    }
422
423
    /**
424
     * @dataProvider providerDATEDIF
425
     *
426
     * @param mixed $expectedResult
427
     */
428
    public function testDATEDIF($expectedResult, ...$args)
429
    {
430
        $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

430
        $result = DateTime::DATEDIF(/** @scrutinizer ignore-type */ ...$args);
Loading history...
431
        self::assertEquals($expectedResult, $result, null, 1E-8);
432
    }
433
434
    public function providerDATEDIF()
435
    {
436
        return require 'data/Calculation/DateTime/DATEDIF.php';
437
    }
438
439
    /**
440
     * @dataProvider providerDAYS360
441
     *
442
     * @param mixed $expectedResult
443
     */
444
    public function testDAYS360($expectedResult, ...$args)
445
    {
446
        $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

446
        $result = DateTime::DAYS360(/** @scrutinizer ignore-type */ ...$args);
Loading history...
447
        self::assertEquals($expectedResult, $result, null, 1E-8);
448
    }
449
450
    public function providerDAYS360()
451
    {
452
        return require 'data/Calculation/DateTime/DAYS360.php';
453
    }
454
455
    /**
456
     * @dataProvider providerYEARFRAC
457
     *
458
     * @param mixed $expectedResult
459
     */
460
    public function testYEARFRAC($expectedResult, ...$args)
461
    {
462
        $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

462
        $result = DateTime::YEARFRAC(/** @scrutinizer ignore-type */ ...$args);
Loading history...
463
        self::assertEquals($expectedResult, $result, null, 1E-8);
464
    }
465
466
    public function providerYEARFRAC()
467
    {
468
        return require 'data/Calculation/DateTime/YEARFRAC.php';
469
    }
470
}
471