Completed
Push — develop ( aa97bb...91573b )
by
unknown
09:37
created

DateTest::providerIsDateTimeFormatCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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(
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
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 providerDateTimeTimestampToExcel1900
52
     */
53 View Code Duplication
    public function testDateTimeTimestampToExcel1900()
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...
54
    {
55
        $result = call_user_func(
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
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,'timestampToExcel'), $args);
63
        $this->assertEquals($expectedResult, $result, null, 1E-5);
64
    }
65
66
    public function providerDateTimeTimestampToExcel1900()
67
    {
68
        return include 'rawTestData/Shared/Date/TimestampToExcel1900.php';
69
    }
70
71
    /**
72
     * @dataProvider providerDateTimeDateTimeToExcel
73
     */
74 View Code Duplication
    public function testDateTimeDateTimeToExcel()
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...
75
    {
76
        $result = call_user_func(
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
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,'dateTimeToExcel'), $args);
84
        $this->assertEquals($expectedResult, $result, null, 1E-5);
85
    }
86
87
    public function providerDateTimeDateTimeToExcel()
88
    {
89
        return include 'rawTestData/Shared/Date/DateTimeToExcel.php';
90
    }
91
92
    /**
93
     * @dataProvider providerDateTimeFormattedPHPToExcel1900
94
     */
95 View Code Duplication
    public function testDateTimeFormattedPHPToExcel1900()
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...
96
    {
97
        $result = call_user_func(
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
98
            array(Date::class,'setExcelCalendar'),
99
            Date::CALENDAR_WINDOWS_1900
100
        );
101
102
        $args = func_get_args();
103
        $expectedResult = array_pop($args);
104
        $result = call_user_func_array(array(Date::class,'formattedPHPToExcel'), $args);
105
        $this->assertEquals($expectedResult, $result, null, 1E-5);
106
    }
107
108
    public function providerDateTimeFormattedPHPToExcel1900()
109
    {
110
        return include 'rawTestData/Shared/Date/FormattedPHPToExcel1900.php';
111
    }
112
113
    /**
114
     * @dataProvider providerDateTimeExcelToTimestamp1904
115
     */
116 View Code Duplication
    public function testDateTimeExcelToTimestamp1904()
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...
117
    {
118
        $result = call_user_func(
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
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,'excelToTimestamp'), $args);
126
        $this->assertEquals($expectedResult, $result);
127
    }
128
129
    public function providerDateTimeExcelToTimestamp1904()
130
    {
131
        return include 'rawTestData/Shared/Date/ExcelToTimestamp1904.php';
132
    }
133
134
    /**
135
     * @dataProvider providerDateTimeTimestampToExcel1904
136
     */
137 View Code Duplication
    public function testDateTimeTimestampToExcel1904()
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...
138
    {
139
        $result = call_user_func(
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
140
            array(Date::class,'setExcelCalendar'),
141
            Date::CALENDAR_MAC_1904
142
        );
143
144
        $args = func_get_args();
145
        $expectedResult = array_pop($args);
146
        $result = call_user_func_array(array(Date::class,'timestampToExcel'), $args);
147
        $this->assertEquals($expectedResult, $result, null, 1E-5);
148
    }
149
150
    public function providerDateTimeTimestampToExcel1904()
151
    {
152
        return include 'rawTestData/Shared/Date/TimestampToExcel1904.php';
153
    }
154
155
    /**
156
     * @dataProvider providerIsDateTimeFormatCode
157
     */
158
    public function testIsDateTimeFormatCode()
159
    {
160
        $args = func_get_args();
161
        $expectedResult = array_pop($args);
162
        $result = call_user_func_array(array(Date::class,'isDateTimeFormatCode'), $args);
163
        $this->assertEquals($expectedResult, $result);
164
    }
165
166
    public function providerIsDateTimeFormatCode()
167
    {
168
        return include 'rawTestData/Shared/Date/FormatCodes.php';
169
    }
170
171
    /**
172
     * @dataProvider providerDateTimeExcelToTimestamp1900Timezone
173
     */
174 View Code Duplication
    public function testDateTimeExcelToTimestamp1900Timezone()
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...
175
    {
176
        $result = call_user_func(
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
177
            array(Date::class,'setExcelCalendar'),
178
            Date::CALENDAR_WINDOWS_1900
179
        );
180
181
        $args = func_get_args();
182
        $expectedResult = array_pop($args);
183
        $result = call_user_func_array(array(Date::class,'excelToTimestamp'), $args);
184
        $this->assertEquals($expectedResult, $result);
185
    }
186
187
    public function providerDateTimeExcelToTimestamp1900Timezone()
188
    {
189
        return include 'rawTestData/Shared/Date/ExcelToTimestamp1900Timezone.php';
190
    }
191
}
192