11
11
use PhpOffice \PhpSpreadsheet \Shared \Date ;
12
12
use PhpOffice \PhpSpreadsheet \Spreadsheet ;
13
13
use PhpOffice \PhpSpreadsheet \Style \NumberFormat ;
14
+ use PHPUnit \Framework \Attributes \DataProvider ;
14
15
use PHPUnit \Framework \TestCase ;
15
16
16
17
class DateTest extends TestCase
@@ -51,7 +52,7 @@ public function testSetExcelCalendarWithInvalidValue(): void
51
52
self ::assertFalse ($ result );
52
53
}
53
54
54
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerDateTimeExcelToTimestamp1900 ' )]
55
+ #[DataProvider('providerDateTimeExcelToTimestamp1900 ' )]
55
56
public function testDateTimeExcelToTimestamp1900 (float |int $ expectedResult , float |int $ excelDateTimeValue ): void
56
57
{
57
58
if ($ expectedResult > PHP_INT_MAX || $ expectedResult < PHP_INT_MIN ) {
@@ -68,7 +69,7 @@ public static function providerDateTimeExcelToTimestamp1900(): array
68
69
return require 'tests/data/Shared/Date/ExcelToTimestamp1900.php ' ;
69
70
}
70
71
71
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerDateTimeTimestampToExcel1900 ' )]
72
+ #[DataProvider('providerDateTimeTimestampToExcel1900 ' )]
72
73
public function testDateTimeTimestampToExcel1900 (float |int $ expectedResult , float |int |string $ unixTimestamp ): void
73
74
{
74
75
Date::setExcelCalendar (Date::CALENDAR_WINDOWS_1900 );
@@ -82,7 +83,7 @@ public static function providerDateTimeTimestampToExcel1900(): array
82
83
return require 'tests/data/Shared/Date/TimestampToExcel1900.php ' ;
83
84
}
84
85
85
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerDateTimeDateTimeToExcel ' )]
86
+ #[DataProvider('providerDateTimeDateTimeToExcel ' )]
86
87
public function testDateTimeDateTimeToExcel (float |int $ expectedResult , DateTimeInterface $ dateTimeObject ): void
87
88
{
88
89
Date::setExcelCalendar (Date::CALENDAR_WINDOWS_1900 );
@@ -99,7 +100,7 @@ public static function providerDateTimeDateTimeToExcel(): array
99
100
/**
100
101
* @param array{0: int, 1: int, 2: int, 3: int, 4: int, 5: float|int} $args Array containing year/month/day/hours/minutes/seconds
101
102
*/
102
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerDateTimeFormattedPHPToExcel1900 ' )]
103
+ #[DataProvider('providerDateTimeFormattedPHPToExcel1900 ' )]
103
104
public function testDateTimeFormattedPHPToExcel1900 (mixed $ expectedResult , ...$ args ): void
104
105
{
105
106
Date::setExcelCalendar (Date::CALENDAR_WINDOWS_1900 );
@@ -113,7 +114,7 @@ public static function providerDateTimeFormattedPHPToExcel1900(): array
113
114
return require 'tests/data/Shared/Date/FormattedPHPToExcel1900.php ' ;
114
115
}
115
116
116
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerDateTimeExcelToTimestamp1904 ' )]
117
+ #[DataProvider('providerDateTimeExcelToTimestamp1904 ' )]
117
118
public function testDateTimeExcelToTimestamp1904 (float |int $ expectedResult , float |int $ excelDateTimeValue ): void
118
119
{
119
120
if ($ expectedResult > PHP_INT_MAX || $ expectedResult < PHP_INT_MIN ) {
@@ -130,7 +131,7 @@ public static function providerDateTimeExcelToTimestamp1904(): array
130
131
return require 'tests/data/Shared/Date/ExcelToTimestamp1904.php ' ;
131
132
}
132
133
133
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerDateTimeTimestampToExcel1904 ' )]
134
+ #[DataProvider('providerDateTimeTimestampToExcel1904 ' )]
134
135
public function testDateTimeTimestampToExcel1904 (mixed $ expectedResult , float |int |string $ unixTimestamp ): void
135
136
{
136
137
Date::setExcelCalendar (Date::CALENDAR_MAC_1904 );
@@ -144,7 +145,7 @@ public static function providerDateTimeTimestampToExcel1904(): array
144
145
return require 'tests/data/Shared/Date/TimestampToExcel1904.php ' ;
145
146
}
146
147
147
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerIsDateTimeFormatCode ' )]
148
+ #[DataProvider('providerIsDateTimeFormatCode ' )]
148
149
public function testIsDateTimeFormatCode (mixed $ expectedResult , string $ format ): void
149
150
{
150
151
$ result = Date::isDateTimeFormatCode ($ format );
@@ -156,7 +157,7 @@ public static function providerIsDateTimeFormatCode(): array
156
157
return require 'tests/data/Shared/Date/FormatCodes.php ' ;
157
158
}
158
159
159
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerDateTimeExcelToTimestamp1900Timezone ' )]
160
+ #[DataProvider('providerDateTimeExcelToTimestamp1900Timezone ' )]
160
161
public function testDateTimeExcelToTimestamp1900Timezone (float |int $ expectedResult , float |int $ excelDateTimeValue , string $ timezone ): void
161
162
{
162
163
if ($ expectedResult > PHP_INT_MAX || $ expectedResult < PHP_INT_MIN ) {
@@ -240,6 +241,27 @@ public function testVarious(): void
240
241
$ spreadsheet ->disconnectWorksheets ();
241
242
}
242
243
244
+ public function testArray (): void
245
+ {
246
+ $ spreadsheet = new Spreadsheet ();
247
+ $ spreadsheet ->returnArrayAsArray ();
248
+ $ sheet = $ spreadsheet ->getActiveSheet ();
249
+ $ sheet ->setCellValue ('A1 ' , 45000 );
250
+ $ sheet ->setCellValue ('A2 ' , 44000 );
251
+ $ sheet ->setCellValue ('A3 ' , 46000 );
252
+ $ sheet ->setCellValue ('C1 ' , '=SORT(A1:A3) ' );
253
+ $ sheet ->setCellValue ('D1 ' , '=SORT(A1:A3) ' );
254
+ $ sheet ->getStyle ('C1 ' )
255
+ ->getNumberFormat ()
256
+ ->setFormatCode ('yyyy-mm-dd ' );
257
+ self ::assertTrue (Date::isDateTime ($ sheet ->getCell ('C1 ' )));
258
+ self ::assertFalse (Date::isDateTime ($ sheet ->getCell ('D1 ' )));
259
+ self ::assertIsArray (
260
+ $ sheet ->getCell ('C1 ' )->getCalculatedValue ()
261
+ );
262
+ $ spreadsheet ->disconnectWorksheets ();
263
+ }
264
+
243
265
public function testRoundMicroseconds (): void
244
266
{
245
267
$ dti = new DateTime ('2000-01-02 03:04:05.999999 ' );
0 commit comments