diff --git a/tests/PhpSpreadsheetTests/Cell/AddressHelperTest.php b/tests/PhpSpreadsheetTests/Cell/AddressHelperTest.php index 9b21767be3..ffe0e05f8b 100644 --- a/tests/PhpSpreadsheetTests/Cell/AddressHelperTest.php +++ b/tests/PhpSpreadsheetTests/Cell/AddressHelperTest.php @@ -26,9 +26,13 @@ public function providerR1C1ConversionToA1Absolute() /** * @dataProvider providerR1C1ConversionToA1Relative */ - public function testR1C1ConversionToA1Relative(string $expectedValue, string $address, ?int $row = null, ?int $column = null): void - { - $args = [$address]; + public function testR1C1ConversionToA1Relative( + string $expectedValue, + string $address, + ?int $row = null, + ?int $column = null + ): void { + $args = []; if ($row !== null) { $args[] = $row; } @@ -36,7 +40,7 @@ public function testR1C1ConversionToA1Relative(string $expectedValue, string $ad $args[] = $column; } - $actualValue = AddressHelper::convertToA1(...$args); + $actualValue = AddressHelper::convertToA1($address, ...$args); self::assertSame($expectedValue, $actualValue); } diff --git a/tests/PhpSpreadsheetTests/Cell/CoordinateTest.php b/tests/PhpSpreadsheetTests/Cell/CoordinateTest.php index 8e0e98a90d..159af3b9a2 100644 --- a/tests/PhpSpreadsheetTests/Cell/CoordinateTest.php +++ b/tests/PhpSpreadsheetTests/Cell/CoordinateTest.php @@ -232,10 +232,11 @@ public function providerSplitRange() * @dataProvider providerBuildRange * * @param mixed $expectedResult + * @param mixed $rangeSets */ - public function testBuildRange($expectedResult, ...$args): void + public function testBuildRange($expectedResult, $rangeSets): void { - $result = Coordinate::buildRange(...$args); + $result = Coordinate::buildRange($rangeSets); self::assertEquals($expectedResult, $result); } @@ -248,7 +249,16 @@ public function testBuildRangeInvalid(): void { $this->expectException(TypeError::class); - $cellRange = ''; + $cellRange = null; + Coordinate::buildRange($cellRange); + } + + public function testBuildRangeInvalid2(): void + { + $this->expectException(Exception::class); + $this->expectExceptionMessage('Range does not contain any information'); + + $cellRange = []; Coordinate::buildRange($cellRange); } @@ -342,10 +352,11 @@ public function providerInvalidRange() * @dataProvider providerMergeRangesInCollection * * @param mixed $expectedResult + * @param mixed $rangeSets */ - public function testMergeRangesInCollection($expectedResult, ...$args): void + public function testMergeRangesInCollection($expectedResult, $rangeSets): void { - $result = Coordinate::mergeRangesInCollection(...$args); + $result = Coordinate::mergeRangesInCollection($rangeSets); self::assertEquals($expectedResult, $result); } diff --git a/tests/PhpSpreadsheetTests/Shared/CodePageTest.php b/tests/PhpSpreadsheetTests/Shared/CodePageTest.php index 2bdbda72f7..eb12188983 100644 --- a/tests/PhpSpreadsheetTests/Shared/CodePageTest.php +++ b/tests/PhpSpreadsheetTests/Shared/CodePageTest.php @@ -12,10 +12,11 @@ class CodePageTest extends TestCase * @dataProvider providerCodePage * * @param mixed $expectedResult + * @param mixed $codePageIndex */ - public function testCodePageNumberToName($expectedResult, ...$args): void + public function testCodePageNumberToName($expectedResult, $codePageIndex): void { - $result = CodePage::numberToName(...$args); + $result = CodePage::numberToName($codePageIndex); self::assertEquals($expectedResult, $result); } diff --git a/tests/PhpSpreadsheetTests/Shared/DateTest.php b/tests/PhpSpreadsheetTests/Shared/DateTest.php index 550e2f6a9c..4ab7461b12 100644 --- a/tests/PhpSpreadsheetTests/Shared/DateTest.php +++ b/tests/PhpSpreadsheetTests/Shared/DateTest.php @@ -39,7 +39,7 @@ public function testSetExcelCalendar(): void public function testSetExcelCalendarWithInvalidValue(): void { - $unsupportedCalendar = '2012'; + $unsupportedCalendar = 2012; $result = Date::setExcelCalendar($unsupportedCalendar); self::assertFalse($result); } @@ -48,15 +48,16 @@ public function testSetExcelCalendarWithInvalidValue(): void * @dataProvider providerDateTimeExcelToTimestamp1900 * * @param mixed $expectedResult + * @param mixed $excelDateTimeValue */ - public function testDateTimeExcelToTimestamp1900($expectedResult, ...$args): void + public function testDateTimeExcelToTimestamp1900($expectedResult, $excelDateTimeValue): void { if (is_numeric($expectedResult) && ($expectedResult > PHP_INT_MAX || $expectedResult < PHP_INT_MIN)) { self::markTestSkipped('Test invalid on 32-bit system.'); } Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); - $result = Date::excelToTimestamp(...$args); + $result = Date::excelToTimestamp($excelDateTimeValue); self::assertEquals($expectedResult, $result); } @@ -69,12 +70,13 @@ public function providerDateTimeExcelToTimestamp1900() * @dataProvider providerDateTimeTimestampToExcel1900 * * @param mixed $expectedResult + * @param mixed $unixTimestamp */ - public function testDateTimeTimestampToExcel1900($expectedResult, ...$args): void + public function testDateTimeTimestampToExcel1900($expectedResult, $unixTimestamp): void { Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); - $result = Date::timestampToExcel(...$args); + $result = Date::timestampToExcel($unixTimestamp); self::assertEqualsWithDelta($expectedResult, $result, 1E-5); } @@ -87,12 +89,13 @@ public function providerDateTimeTimestampToExcel1900() * @dataProvider providerDateTimeDateTimeToExcel * * @param mixed $expectedResult + * @param mixed $dateTimeObject */ - public function testDateTimeDateTimeToExcel($expectedResult, ...$args): void + public function testDateTimeDateTimeToExcel($expectedResult, $dateTimeObject): void { Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); - $result = Date::dateTimeToExcel(...$args); + $result = Date::dateTimeToExcel($dateTimeObject); self::assertEqualsWithDelta($expectedResult, $result, 1E-5); } @@ -123,15 +126,16 @@ public function providerDateTimeFormattedPHPToExcel1900() * @dataProvider providerDateTimeExcelToTimestamp1904 * * @param mixed $expectedResult + * @param mixed $excelDateTimeValue */ - public function testDateTimeExcelToTimestamp1904($expectedResult, ...$args): void + public function testDateTimeExcelToTimestamp1904($expectedResult, $excelDateTimeValue): void { if (is_numeric($expectedResult) && ($expectedResult > PHP_INT_MAX || $expectedResult < PHP_INT_MIN)) { self::markTestSkipped('Test invalid on 32-bit system.'); } Date::setExcelCalendar(Date::CALENDAR_MAC_1904); - $result = Date::excelToTimestamp(...$args); + $result = Date::excelToTimestamp($excelDateTimeValue); self::assertEquals($expectedResult, $result); } @@ -144,12 +148,13 @@ public function providerDateTimeExcelToTimestamp1904() * @dataProvider providerDateTimeTimestampToExcel1904 * * @param mixed $expectedResult + * @param mixed $unixTimestamp */ - public function testDateTimeTimestampToExcel1904($expectedResult, ...$args): void + public function testDateTimeTimestampToExcel1904($expectedResult, $unixTimestamp): void { Date::setExcelCalendar(Date::CALENDAR_MAC_1904); - $result = Date::timestampToExcel(...$args); + $result = Date::timestampToExcel($unixTimestamp); self::assertEqualsWithDelta($expectedResult, $result, 1E-5); } @@ -178,15 +183,17 @@ public function providerIsDateTimeFormatCode() * @dataProvider providerDateTimeExcelToTimestamp1900Timezone * * @param mixed $expectedResult + * @param mixed $excelDateTimeValue + * @param mixed $timezone */ - public function testDateTimeExcelToTimestamp1900Timezone($expectedResult, ...$args): void + public function testDateTimeExcelToTimestamp1900Timezone($expectedResult, $excelDateTimeValue, $timezone): void { if (is_numeric($expectedResult) && ($expectedResult > PHP_INT_MAX || $expectedResult < PHP_INT_MIN)) { self::markTestSkipped('Test invalid on 32-bit system.'); } Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); - $result = Date::excelToTimestamp(...$args); + $result = Date::excelToTimestamp($excelDateTimeValue, $timezone); self::assertEquals($expectedResult, $result); } @@ -202,29 +209,37 @@ public function testVarious(): void self::assertTrue((bool) Date::stringToExcel('2019-02-28')); self::assertTrue((bool) Date::stringToExcel('2019-02-28 11:18')); self::assertFalse(Date::stringToExcel('2019-02-28 11:71')); + $date = Date::PHPToExcel('2020-01-01'); self::assertEquals(43831.0, $date); + $spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('B1', 'x'); $val = $sheet->getCell('B1')->getValue(); self::assertFalse(Date::timestampToExcel($val)); + $cell = $sheet->getCell('A1'); self::assertNotNull($cell); + $cell->setValue($date); $sheet->getStyle('A1') ->getNumberFormat() ->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME); self::assertTrue(null !== $cell && Date::isDateTime($cell)); + $cella2 = $sheet->getCell('A2'); self::assertNotNull($cella2); + $cella2->setValue('=A1+2'); $sheet->getStyle('A2') ->getNumberFormat() ->setFormatCode(NumberFormat::FORMAT_DATE_DATETIME); self::assertTrue(null !== $cella2 && Date::isDateTime($cella2)); + $cella3 = $sheet->getCell('A3'); self::assertNotNull($cella3); + $cella3->setValue('=A1+4'); $sheet->getStyle('A3') ->getNumberFormat()