Completed
Branch develop (b42baf)
by Adrien
11:23
created

DateTimeTest::testDATEtoPHP()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 7
loc 7
rs 9.4285
1
<?php
2
3
namespace PhpSpreadsheetTests\Calculation;
4
5
use PhpSpreadsheet\Calculation\DateTime;
6
use PhpSpreadsheet\Calculation\Functions;
7
use PhpSpreadsheet\Shared\Date;
8
9
/**
10
 * Class DateTimeTest
11
 */
12
class DateTimeTest extends \PHPUnit_Framework_TestCase
13
{
14
    public function setUp()
15
    {
16
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
17
    }
18
19
    /**
20
     * @dataProvider providerDATE
21
     */
22
    public function testDATE()
23
    {
24
        $args = func_get_args();
25
        $expectedResult = array_pop($args);
26
        $result = call_user_func_array([DateTime::class, 'DATE'], $args);
27
        $this->assertEquals($expectedResult, $result, null, 1E-8);
28
    }
29
30
    public function providerDATE()
31
    {
32
        return require 'data/Calculation/DateTime/DATE.php';
33
    }
34
35 View Code Duplication
    public function testDATEtoPHP()
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...
36
    {
37
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
38
        $result = DateTime::DATE(2012, 1, 31);
39
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
40
        $this->assertEquals(1327968000, $result, null, 1E-8);
41
    }
42
43 View Code Duplication
    public function testDATEtoPHPObject()
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...
44
    {
45
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
46
        $result = DateTime::DATE(2012, 1, 31);
47
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
48
        //    Must return an object...
49
        $this->assertTrue(is_object($result));
50
        //    ... of the correct type
51
        $this->assertTrue(is_a($result, 'DateTime'));
52
        //    ... with the correct value
53
        $this->assertEquals($result->format('d-M-Y'), '31-Jan-2012');
54
    }
55
56 View Code Duplication
    public function testDATEwith1904Calendar()
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...
57
    {
58
        Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
59
        $result = DateTime::DATE(1918, 11, 11);
60
        Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
61
        $this->assertEquals($result, 5428);
62
    }
63
64 View Code Duplication
    public function testDATEwith1904CalendarError()
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...
65
    {
66
        Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
67
        $result = DateTime::DATE(1901, 1, 31);
68
        Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
69
        $this->assertEquals($result, '#NUM!');
70
    }
71
72
    /**
73
     * @dataProvider providerDATEVALUE
74
     */
75
    public function testDATEVALUE()
76
    {
77
        $args = func_get_args();
78
        $expectedResult = array_pop($args);
79
        $result = call_user_func_array([DateTime::class, 'DATEVALUE'], $args);
80
        $this->assertEquals($expectedResult, $result, null, 1E-8);
81
    }
82
83
    public function providerDATEVALUE()
84
    {
85
        return require 'data/Calculation/DateTime/DATEVALUE.php';
86
    }
87
88 View Code Duplication
    public function testDATEVALUEtoPHP()
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...
89
    {
90
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
91
        $result = DateTime::DATEVALUE('2012-1-31');
92
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
93
        $this->assertEquals(1327968000, $result, null, 1E-8);
94
    }
95
96
    public function testDATEVALUEtoPHPObject()
97
    {
98
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
99
        $result = DateTime::DATEVALUE('2012-1-31');
100
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
101
        //    Must return an object...
102
        $this->assertTrue(is_object($result));
103
        //    ... of the correct type
104
        $this->assertTrue(is_a($result, 'DateTime'));
105
        //    ... with the correct value
106
        $this->assertEquals($result->format('d-M-Y'), '31-Jan-2012');
107
    }
108
109
    /**
110
     * @dataProvider providerYEAR
111
     */
112
    public function testYEAR()
113
    {
114
        $args = func_get_args();
115
        $expectedResult = array_pop($args);
116
        $result = call_user_func_array([DateTime::class, 'YEAR'], $args);
117
        $this->assertEquals($expectedResult, $result, null, 1E-8);
118
    }
119
120
    public function providerYEAR()
121
    {
122
        return require 'data/Calculation/DateTime/YEAR.php';
123
    }
124
125
    /**
126
     * @dataProvider providerMONTH
127
     */
128
    public function testMONTH()
129
    {
130
        $args = func_get_args();
131
        $expectedResult = array_pop($args);
132
        $result = call_user_func_array([DateTime::class, 'MONTHOFYEAR'], $args);
133
        $this->assertEquals($expectedResult, $result, null, 1E-8);
134
    }
135
136
    public function providerMONTH()
137
    {
138
        return require 'data/Calculation/DateTime/MONTH.php';
139
    }
140
141
    /**
142
     * @dataProvider providerWEEKNUM
143
     * @group fail19
144
     */
145
    public function testWEEKNUM()
146
    {
147
        $this->markTestIncomplete('TODO: This test should be fixed');
148
149
        $args = func_get_args();
150
        $expectedResult = array_pop($args);
151
        $result = call_user_func_array([DateTime::class, 'WEEKOFYEAR'], $args);
152
        $this->assertEquals($expectedResult, $result, null, 1E-8);
153
    }
154
155
    public function providerWEEKNUM()
156
    {
157
        return require 'data/Calculation/DateTime/WEEKNUM.php';
158
    }
159
160
    /**
161
     * @dataProvider providerWEEKDAY
162
     * @group fail19
163
     */
164
    public function testWEEKDAY()
165
    {
166
        $this->markTestIncomplete('TODO: This test should be fixed');
167
168
        $args = func_get_args();
169
        $expectedResult = array_pop($args);
170
        $result = call_user_func_array([DateTime::class, 'DAYOFWEEK'], $args);
171
        $this->assertEquals($expectedResult, $result, null, 1E-8);
172
    }
173
174
    public function providerWEEKDAY()
175
    {
176
        return require 'data/Calculation/DateTime/WEEKDAY.php';
177
    }
178
179
    /**
180
     * @dataProvider providerDAY
181
     */
182
    public function testDAY()
183
    {
184
        $args = func_get_args();
185
        $expectedResult = array_pop($args);
186
        $result = call_user_func_array([DateTime::class, 'DAYOFMONTH'], $args);
187
        $this->assertEquals($expectedResult, $result, 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
    public function testTIME()
199
    {
200
        $args = func_get_args();
201
        $expectedResult = array_pop($args);
202
        $result = call_user_func_array([DateTime::class, 'TIME'], $args);
203
        $this->assertEquals($expectedResult, $result, null, 1E-8);
204
    }
205
206
    public function providerTIME()
207
    {
208
        return require 'data/Calculation/DateTime/TIME.php';
209
    }
210
211 View Code Duplication
    public function testTIMEtoPHP()
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...
212
    {
213
        $this->markTestIncomplete('TODO: This test should be fixed');
214
215
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
216
        $result = DateTime::TIME(7, 30, 20);
217
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
218
        $this->assertEquals(27020, $result, null, 1E-8);
219
    }
220
221 View Code Duplication
    public function testTIMEtoPHPObject()
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...
222
    {
223
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
224
        $result = DateTime::TIME(7, 30, 20);
225
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
226
        //    Must return an object...
227
        $this->assertTrue(is_object($result));
228
        //    ... of the correct type
229
        $this->assertTrue(is_a($result, 'DateTime'));
230
        //    ... with the correct value
231
        $this->assertEquals($result->format('H:i:s'), '07:30:20');
232
    }
233
234
    /**
235
     * @dataProvider providerTIMEVALUE
236
     */
237
    public function testTIMEVALUE()
238
    {
239
        $args = func_get_args();
240
        $expectedResult = array_pop($args);
241
        $result = call_user_func_array([DateTime::class, 'TIMEVALUE'], $args);
242
        $this->assertEquals($expectedResult, $result, null, 1E-8);
243
    }
244
245
    public function providerTIMEVALUE()
246
    {
247
        return require 'data/Calculation/DateTime/TIMEVALUE.php';
248
    }
249
250 View Code Duplication
    public function testTIMEVALUEtoPHP()
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...
251
    {
252
        $this->markTestIncomplete('TODO: This test should be fixed');
253
254
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
255
        $result = DateTime::TIMEVALUE('7:30:20');
256
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
257
        $this->assertEquals(23420, $result, null, 1E-8);
258
    }
259
260
    public function testTIMEVALUEtoPHPObject()
261
    {
262
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
263
        $result = DateTime::TIMEVALUE('7:30:20');
264
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
265
        //    Must return an object...
266
        $this->assertTrue(is_object($result));
267
        //    ... of the correct type
268
        $this->assertTrue(is_a($result, 'DateTime'));
269
        //    ... with the correct value
270
        $this->assertEquals($result->format('H:i:s'), '07:30:20');
271
    }
272
273
    /**
274
     * @dataProvider providerHOUR
275
     */
276
    public function testHOUR()
277
    {
278
        $args = func_get_args();
279
        $expectedResult = array_pop($args);
280
        $result = call_user_func_array([DateTime::class, 'HOUROFDAY'], $args);
281
        $this->assertEquals($expectedResult, $result, null, 1E-8);
282
    }
283
284
    public function providerHOUR()
285
    {
286
        return require 'data/Calculation/DateTime/HOUR.php';
287
    }
288
289
    /**
290
     * @dataProvider providerMINUTE
291
     */
292
    public function testMINUTE()
293
    {
294
        $this->markTestIncomplete('TODO: This test should be fixed');
295
296
        $args = func_get_args();
297
        $expectedResult = array_pop($args);
298
        $result = call_user_func_array([DateTime::class, 'MINUTEOFHOUR'], $args);
299
        $this->assertEquals($expectedResult, $result, null, 1E-8);
300
    }
301
302
    public function providerMINUTE()
303
    {
304
        return require 'data/Calculation/DateTime/MINUTE.php';
305
    }
306
307
    /**
308
     * @dataProvider providerSECOND
309
     */
310
    public function testSECOND()
311
    {
312
        $this->markTestIncomplete('TODO: This test should be fixed');
313
314
        $args = func_get_args();
315
        $expectedResult = array_pop($args);
316
        $result = call_user_func_array([DateTime::class, 'SECONDOFMINUTE'], $args);
317
        $this->assertEquals($expectedResult, $result, null, 1E-8);
318
    }
319
320
    public function providerSECOND()
321
    {
322
        return require 'data/Calculation/DateTime/SECOND.php';
323
    }
324
325
    /**
326
     * @dataProvider providerNETWORKDAYS
327
     */
328
    public function testNETWORKDAYS()
329
    {
330
        $args = func_get_args();
331
        $expectedResult = array_pop($args);
332
        $result = call_user_func_array([DateTime::class, 'NETWORKDAYS'], $args);
333
        $this->assertEquals($expectedResult, $result, null, 1E-8);
334
    }
335
336
    public function providerNETWORKDAYS()
337
    {
338
        return require 'data/Calculation/DateTime/NETWORKDAYS.php';
339
    }
340
341
    /**
342
     * @dataProvider providerWORKDAY
343
     */
344
    public function testWORKDAY()
345
    {
346
        $args = func_get_args();
347
        $expectedResult = array_pop($args);
348
        $result = call_user_func_array([DateTime::class, 'WORKDAY'], $args);
349
        $this->assertEquals($expectedResult, $result, null, 1E-8);
350
    }
351
352
    public function providerWORKDAY()
353
    {
354
        return require 'data/Calculation/DateTime/WORKDAY.php';
355
    }
356
357
    /**
358
     * @dataProvider providerEDATE
359
     */
360
    public function testEDATE()
361
    {
362
        $args = func_get_args();
363
        $expectedResult = array_pop($args);
364
        $result = call_user_func_array([DateTime::class, 'EDATE'], $args);
365
        $this->assertEquals($expectedResult, $result, null, 1E-8);
366
    }
367
368
    public function providerEDATE()
369
    {
370
        return require 'data/Calculation/DateTime/EDATE.php';
371
    }
372
373 View Code Duplication
    public function testEDATEtoPHP()
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...
374
    {
375
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
376
        $result = DateTime::EDATE('2012-1-26', -1);
377
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
378
        $this->assertEquals(1324857600, $result, null, 1E-8);
379
    }
380
381 View Code Duplication
    public function testEDATEtoPHPObject()
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...
382
    {
383
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
384
        $result = DateTime::EDATE('2012-1-26', -1);
385
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
386
        //    Must return an object...
387
        $this->assertTrue(is_object($result));
388
        //    ... of the correct type
389
        $this->assertTrue(is_a($result, 'DateTime'));
390
        //    ... with the correct value
391
        $this->assertEquals($result->format('d-M-Y'), '26-Dec-2011');
392
    }
393
394
    /**
395
     * @dataProvider providerEOMONTH
396
     */
397
    public function testEOMONTH()
398
    {
399
        $args = func_get_args();
400
        $expectedResult = array_pop($args);
401
        $result = call_user_func_array([DateTime::class, 'EOMONTH'], $args);
402
        $this->assertEquals($expectedResult, $result, null, 1E-8);
403
    }
404
405
    public function providerEOMONTH()
406
    {
407
        return require 'data/Calculation/DateTime/EOMONTH.php';
408
    }
409
410 View Code Duplication
    public function testEOMONTHtoPHP()
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...
411
    {
412
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_NUMERIC);
413
        $result = DateTime::EOMONTH('2012-1-26', -1);
414
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
415
        $this->assertEquals(1325289600, $result, null, 1E-8);
416
    }
417
418 View Code Duplication
    public function testEOMONTHtoPHPObject()
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...
419
    {
420
        Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
421
        $result = DateTime::EOMONTH('2012-1-26', -1);
422
        Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
423
        //    Must return an object...
424
        $this->assertTrue(is_object($result));
425
        //    ... of the correct type
426
        $this->assertTrue(is_a($result, 'DateTime'));
427
        //    ... with the correct value
428
        $this->assertEquals($result->format('d-M-Y'), '31-Dec-2011');
429
    }
430
431
    /**
432
     * @dataProvider providerDATEDIF
433
     * @group fail19
434
     */
435
    public function testDATEDIF()
436
    {
437
        $this->markTestIncomplete('TODO: This test should be fixed');
438
439
        $args = func_get_args();
440
        $expectedResult = array_pop($args);
441
        $result = call_user_func_array([DateTime::class, 'DATEDIF'], $args);
442
        $this->assertEquals($expectedResult, $result, null, 1E-8);
443
    }
444
445
    public function providerDATEDIF()
446
    {
447
        return require 'data/Calculation/DateTime/DATEDIF.php';
448
    }
449
450
    /**
451
     * @dataProvider providerDAYS360
452
     */
453
    public function testDAYS360()
454
    {
455
        $args = func_get_args();
456
        $expectedResult = array_pop($args);
457
        $result = call_user_func_array([DateTime::class, 'DAYS360'], $args);
458
        $this->assertEquals($expectedResult, $result, null, 1E-8);
459
    }
460
461
    public function providerDAYS360()
462
    {
463
        return require 'data/Calculation/DateTime/DAYS360.php';
464
    }
465
466
    /**
467
     * @dataProvider providerYEARFRAC
468
     * @group fail19
469
     */
470
    public function testYEARFRAC()
471
    {
472
        $this->markTestIncomplete('TODO: This test should be fixed');
473
474
        $args = func_get_args();
475
        $expectedResult = array_pop($args);
476
        $result = call_user_func_array([DateTime::class, 'YEARFRAC'], $args);
477
        $this->assertEquals($expectedResult, $result, null, 1E-8);
478
    }
479
480
    public function providerYEARFRAC()
481
    {
482
        return require 'data/Calculation/DateTime/YEARFRAC.php';
483
    }
484
}
485