1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpSpreadsheet\Tests\Shared; |
4
|
|
|
|
5
|
|
|
use PHPExcel\Shared\Date; |
6
|
|
|
|
7
|
|
|
class DateTest extends \PHPUnit_Framework_TestCase |
8
|
|
|
{ |
9
|
|
|
public function testSetExcelCalendar() |
10
|
|
|
{ |
11
|
|
|
$calendarValues = array( |
12
|
|
|
Date::CALENDAR_MAC_1904, |
13
|
|
|
Date::CALENDAR_WINDOWS_1900, |
14
|
|
|
); |
15
|
|
|
|
16
|
|
|
foreach ($calendarValues as $calendarValue) { |
17
|
|
|
$result = call_user_func(array(Date::class,'setExcelCalendar'), $calendarValue); |
18
|
|
|
$this->assertTrue($result); |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testSetExcelCalendarWithInvalidValue() |
23
|
|
|
{ |
24
|
|
|
$unsupportedCalendar = '2012'; |
25
|
|
|
$result = call_user_func(array(Date::class,'setExcelCalendar'), $unsupportedCalendar); |
26
|
|
|
$this->assertFalse($result); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @dataProvider providerDateTimeExcelToTimestamp1900 |
31
|
|
|
*/ |
32
|
|
|
public function testDateTimeExcelToTimestamp1900() |
33
|
|
|
{ |
34
|
|
|
$result = call_user_func( |
|
|
|
|
35
|
|
|
array(Date::class,'setExcelCalendar'), |
36
|
|
|
Date::CALENDAR_WINDOWS_1900 |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$args = func_get_args(); |
40
|
|
|
$expectedResult = array_pop($args); |
41
|
|
|
$result = call_user_func_array(array(Date::class, 'excelToTimestamp'), $args); |
42
|
|
|
$this->assertEquals($expectedResult, $result); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function providerDateTimeExcelToTimestamp1900() |
46
|
|
|
{ |
47
|
|
|
return include 'rawTestData/Shared/Date/ExcelToTimestamp1900.php'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @dataProvider providerDateTimePHPToExcel1900 |
52
|
|
|
*/ |
53
|
|
View Code Duplication |
public function testDateTimePHPToExcel1900() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$result = call_user_func( |
|
|
|
|
56
|
|
|
array(Date::class,'setExcelCalendar'), |
57
|
|
|
Date::CALENDAR_WINDOWS_1900 |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$args = func_get_args(); |
61
|
|
|
$expectedResult = array_pop($args); |
62
|
|
|
$result = call_user_func_array(array(Date::class,'PHPToExcel'), $args); |
63
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-5); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function providerDateTimePHPToExcel1900() |
67
|
|
|
{ |
68
|
|
|
return include 'rawTestData/Shared/Date/PHPToExcel1900.php'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @dataProvider providerDateTimeFormattedPHPToExcel1900 |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
public function testDateTimeFormattedPHPToExcel1900() |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$result = call_user_func( |
|
|
|
|
77
|
|
|
array(Date::class,'setExcelCalendar'), |
78
|
|
|
Date::CALENDAR_WINDOWS_1900 |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
$args = func_get_args(); |
82
|
|
|
$expectedResult = array_pop($args); |
83
|
|
|
$result = call_user_func_array(array(Date::class,'formattedPHPToExcel'), $args); |
84
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-5); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function providerDateTimeFormattedPHPToExcel1900() |
88
|
|
|
{ |
89
|
|
|
return include 'rawTestData/Shared/Date/FormattedPHPToExcel1900.php'; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @dataProvider providerDateTimeExcelToTimestamp1904 |
94
|
|
|
*/ |
95
|
|
View Code Duplication |
public function testDateTimeExcelToTimestamp1904() |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$result = call_user_func( |
|
|
|
|
98
|
|
|
array(Date::class,'setExcelCalendar'), |
99
|
|
|
Date::CALENDAR_MAC_1904 |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$args = func_get_args(); |
103
|
|
|
$expectedResult = array_pop($args); |
104
|
|
|
$result = call_user_func_array(array(Date::class,'excelToTimestamp'), $args); |
105
|
|
|
$this->assertEquals($expectedResult, $result); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function providerDateTimeExcelToTimestamp1904() |
109
|
|
|
{ |
110
|
|
|
return include 'rawTestData/Shared/Date/ExcelToTimestamp1904.php'; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @dataProvider providerDateTimePHPToExcel1904 |
115
|
|
|
*/ |
116
|
|
View Code Duplication |
public function testDateTimePHPToExcel1904() |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
$result = call_user_func( |
|
|
|
|
119
|
|
|
array(Date::class,'setExcelCalendar'), |
120
|
|
|
Date::CALENDAR_MAC_1904 |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$args = func_get_args(); |
124
|
|
|
$expectedResult = array_pop($args); |
125
|
|
|
$result = call_user_func_array(array(Date::class,'PHPToExcel'), $args); |
126
|
|
|
$this->assertEquals($expectedResult, $result, null, 1E-5); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function providerDateTimePHPToExcel1904() |
130
|
|
|
{ |
131
|
|
|
return include 'rawTestData/Shared/Date/PHPToExcel1904.php'; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @dataProvider providerIsDateTimeFormatCode |
136
|
|
|
*/ |
137
|
|
|
public function testIsDateTimeFormatCode() |
138
|
|
|
{ |
139
|
|
|
$args = func_get_args(); |
140
|
|
|
$expectedResult = array_pop($args); |
141
|
|
|
$result = call_user_func_array(array(Date::class,'isDateTimeFormatCode'), $args); |
142
|
|
|
$this->assertEquals($expectedResult, $result); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function providerIsDateTimeFormatCode() |
146
|
|
|
{ |
147
|
|
|
return include 'rawTestData/Shared/Date/FormatCodes.php'; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @dataProvider providerDateTimeExcelToTimestamp1900Timezone |
152
|
|
|
*/ |
153
|
|
View Code Duplication |
public function testDateTimeExcelToTimestamp1900Timezone() |
|
|
|
|
154
|
|
|
{ |
155
|
|
|
$result = call_user_func( |
|
|
|
|
156
|
|
|
array(Date::class,'setExcelCalendar'), |
157
|
|
|
Date::CALENDAR_WINDOWS_1900 |
158
|
|
|
); |
159
|
|
|
|
160
|
|
|
$args = func_get_args(); |
161
|
|
|
$expectedResult = array_pop($args); |
162
|
|
|
$result = call_user_func_array(array(Date::class,'excelToTimestamp'), $args); |
163
|
|
|
$this->assertEquals($expectedResult, $result); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function providerDateTimeExcelToTimestamp1900Timezone() |
167
|
|
|
{ |
168
|
|
|
return include 'rawTestData/Shared/Date/ExcelToTimestamp1900Timezone.php'; |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.