Passed
Push — master ( 5f7ed9...f1e82a )
by Mark
28:04
created

tests/PhpSpreadsheetTests/Shared/DateTest.php (8 issues)

Labels
Severity
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Shared;
4
5
use PhpOffice\PhpSpreadsheet\Shared\Date;
6
use PHPUnit\Framework\TestCase;
7
8
class DateTest extends TestCase
9
{
10
    public function testSetExcelCalendar()
11
    {
12
        $calendarValues = [
13
            Date::CALENDAR_MAC_1904,
14
            Date::CALENDAR_WINDOWS_1900,
15
        ];
16
17
        foreach ($calendarValues as $calendarValue) {
18
            $result = Date::setExcelCalendar($calendarValue);
19
            self::assertTrue($result);
20
        }
21
    }
22
23
    public function testSetExcelCalendarWithInvalidValue()
24
    {
25
        $unsupportedCalendar = '2012';
26
        $result = Date::setExcelCalendar($unsupportedCalendar);
0 ignored issues
show
$unsupportedCalendar of type string is incompatible with the type integer expected by parameter $baseDate of PhpOffice\PhpSpreadsheet...ate::setExcelCalendar(). ( Ignorable by Annotation )

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

26
        $result = Date::setExcelCalendar(/** @scrutinizer ignore-type */ $unsupportedCalendar);
Loading history...
27
        self::assertFalse($result);
28
    }
29
30
    /**
31
     * @dataProvider providerDateTimeExcelToTimestamp1900
32
     *
33
     * @param mixed $expectedResult
34
     */
35
    public function testDateTimeExcelToTimestamp1900($expectedResult, ...$args)
36
    {
37
        Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
38
39
        $result = Date::excelToTimestamp(...$args);
1 ignored issue
show
$args is expanded, but the parameter $excelTimestamp of PhpOffice\PhpSpreadsheet...ate::excelToTimestamp() 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

39
        $result = Date::excelToTimestamp(/** @scrutinizer ignore-type */ ...$args);
Loading history...
40
        self::assertEquals($expectedResult, $result);
41
    }
42
43
    public function providerDateTimeExcelToTimestamp1900()
44
    {
45
        return require 'data/Shared/Date/ExcelToTimestamp1900.php';
46
    }
47
48
    /**
49
     * @dataProvider providerDateTimeTimestampToExcel1900
50
     *
51
     * @param mixed $expectedResult
52
     */
53
    public function testDateTimeTimestampToExcel1900($expectedResult, ...$args)
54
    {
55
        Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
56
57
        $result = Date::timestampToExcel(...$args);
1 ignored issue
show
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...ate::timestampToExcel() 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

57
        $result = Date::timestampToExcel(/** @scrutinizer ignore-type */ ...$args);
Loading history...
58
        self::assertEquals($expectedResult, $result, null, 1E-5);
59
    }
60
61
    public function providerDateTimeTimestampToExcel1900()
62
    {
63
        return require 'data/Shared/Date/TimestampToExcel1900.php';
64
    }
65
66
    /**
67
     * @dataProvider providerDateTimeDateTimeToExcel
68
     *
69
     * @param mixed $expectedResult
70
     */
71
    public function testDateTimeDateTimeToExcel($expectedResult, ...$args)
72
    {
73
        Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
74
75
        $result = Date::dateTimeToExcel(...$args);
1 ignored issue
show
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...Date::dateTimeToExcel() 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

75
        $result = Date::dateTimeToExcel(/** @scrutinizer ignore-type */ ...$args);
Loading history...
76
        self::assertEquals($expectedResult, $result, null, 1E-5);
77
    }
78
79
    public function providerDateTimeDateTimeToExcel()
80
    {
81
        return require 'data/Shared/Date/DateTimeToExcel.php';
82
    }
83
84
    /**
85
     * @dataProvider providerDateTimeFormattedPHPToExcel1900
86
     *
87
     * @param mixed $expectedResult
88
     */
89
    public function testDateTimeFormattedPHPToExcel1900($expectedResult, ...$args)
90
    {
91
        Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
92
93
        $result = Date::formattedPHPToExcel(...$args);
94
        self::assertEquals($expectedResult, $result, null, 1E-5);
95
    }
96
97
    public function providerDateTimeFormattedPHPToExcel1900()
98
    {
99
        return require 'data/Shared/Date/FormattedPHPToExcel1900.php';
100
    }
101
102
    /**
103
     * @dataProvider providerDateTimeExcelToTimestamp1904
104
     *
105
     * @param mixed $expectedResult
106
     */
107
    public function testDateTimeExcelToTimestamp1904($expectedResult, ...$args)
108
    {
109
        Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
110
111
        $result = Date::excelToTimestamp(...$args);
1 ignored issue
show
$args is expanded, but the parameter $excelTimestamp of PhpOffice\PhpSpreadsheet...ate::excelToTimestamp() 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

111
        $result = Date::excelToTimestamp(/** @scrutinizer ignore-type */ ...$args);
Loading history...
112
        self::assertEquals($expectedResult, $result);
113
    }
114
115
    public function providerDateTimeExcelToTimestamp1904()
116
    {
117
        return require 'data/Shared/Date/ExcelToTimestamp1904.php';
118
    }
119
120
    /**
121
     * @dataProvider providerDateTimeTimestampToExcel1904
122
     *
123
     * @param mixed $expectedResult
124
     */
125
    public function testDateTimeTimestampToExcel1904($expectedResult, ...$args)
126
    {
127
        Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
128
129
        $result = Date::timestampToExcel(...$args);
1 ignored issue
show
$args is expanded, but the parameter $dateValue of PhpOffice\PhpSpreadsheet...ate::timestampToExcel() 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

129
        $result = Date::timestampToExcel(/** @scrutinizer ignore-type */ ...$args);
Loading history...
130
        self::assertEquals($expectedResult, $result, null, 1E-5);
131
    }
132
133
    public function providerDateTimeTimestampToExcel1904()
134
    {
135
        return require 'data/Shared/Date/TimestampToExcel1904.php';
136
    }
137
138
    /**
139
     * @dataProvider providerIsDateTimeFormatCode
140
     *
141
     * @param mixed $expectedResult
142
     */
143
    public function testIsDateTimeFormatCode($expectedResult, ...$args)
144
    {
145
        $result = Date::isDateTimeFormatCode(...$args);
1 ignored issue
show
$args is expanded, but the parameter $pFormatCode of PhpOffice\PhpSpreadsheet...:isDateTimeFormatCode() 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

145
        $result = Date::isDateTimeFormatCode(/** @scrutinizer ignore-type */ ...$args);
Loading history...
146
        self::assertEquals($expectedResult, $result);
147
    }
148
149
    public function providerIsDateTimeFormatCode()
150
    {
151
        return require 'data/Shared/Date/FormatCodes.php';
152
    }
153
154
    /**
155
     * @dataProvider providerDateTimeExcelToTimestamp1900Timezone
156
     *
157
     * @param mixed $expectedResult
158
     */
159
    public function testDateTimeExcelToTimestamp1900Timezone($expectedResult, ...$args)
160
    {
161
        Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
162
163
        $result = Date::excelToTimestamp(...$args);
1 ignored issue
show
$args is expanded, but the parameter $excelTimestamp of PhpOffice\PhpSpreadsheet...ate::excelToTimestamp() 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

163
        $result = Date::excelToTimestamp(/** @scrutinizer ignore-type */ ...$args);
Loading history...
164
        self::assertEquals($expectedResult, $result);
165
    }
166
167
    public function providerDateTimeExcelToTimestamp1900Timezone()
168
    {
169
        return require 'data/Shared/Date/ExcelToTimestamp1900Timezone.php';
170
    }
171
}
172