Skip to content

Commit

Permalink
Minor scrutinizer improvements (#1906)
Browse files Browse the repository at this point in the history
* Minor scrutinizer improvements
* Minor typing improvements
  • Loading branch information
Mark Baker authored Mar 7, 2021
1 parent 2d8c8c8 commit c4ed0ee
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 24 deletions.
12 changes: 8 additions & 4 deletions tests/PhpSpreadsheetTests/Cell/AddressHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@ 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;
}
if ($column !== null) {
$args[] = $column;
}

$actualValue = AddressHelper::convertToA1(...$args);
$actualValue = AddressHelper::convertToA1($address, ...$args);

self::assertSame($expectedValue, $actualValue);
}
Expand Down
21 changes: 16 additions & 5 deletions tests/PhpSpreadsheetTests/Cell/CoordinateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions tests/PhpSpreadsheetTests/Shared/CodePageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
41 changes: 28 additions & 13 deletions tests/PhpSpreadsheetTests/Shared/DateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testSetExcelCalendar(): void

public function testSetExcelCalendarWithInvalidValue(): void
{
$unsupportedCalendar = '2012';
$unsupportedCalendar = 2012;
$result = Date::setExcelCalendar($unsupportedCalendar);
self::assertFalse($result);
}
Expand All @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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()
Expand Down

0 comments on commit c4ed0ee

Please sign in to comment.