From 07271c83aa1881143b8f6df742cc0c6781df7ffc Mon Sep 17 00:00:00 2001 From: oleibman Date: Sat, 25 Dec 2021 09:05:54 -0800 Subject: [PATCH] Rename Two Test Files (#2459) * Rename Two Test Files When I run unit tests only for Reader/Xlsx, phpunit is issuing a deprecation message because the names of 2 files have an extra dot in them and thus don't match the class name in the file. I do not see these warnings when I run the entire test suite. * Remove Phpstan Annotations It was a bit difficult to handle a cast from mixed to string. * Fix Same Phpstan Problem in One Other Test This is the only other test case that tries to cast mixed to string. --- phpstan-baseline.neon | 20 ------------------- .../Reader/Csv/CsvContiguousFilter.php | 5 +---- .../Reader/Csv/CsvContiguousTest.php | 10 +++++++--- ...9bTest.php => NamespaceIssue2109bTest.php} | 5 ++++- ...35Test.php => NamespaceOpenpyxl35Test.php} | 5 ++++- 5 files changed, 16 insertions(+), 29 deletions(-) rename tests/PhpSpreadsheetTests/Reader/Xlsx/{Namespace.Issue2109bTest.php => NamespaceIssue2109bTest.php} (94%) rename tests/PhpSpreadsheetTests/Reader/Xlsx/{Namespace.Openpyxl35Test.php => NamespaceOpenpyxl35Test.php} (95%) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fa9fd68d..5f62562a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -8405,16 +8405,6 @@ parameters: count: 5 path: tests/PhpSpreadsheetTests/NamedRangeTest.php - - - message: "#^Property PhpOffice\\\\PhpSpreadsheetTests\\\\Reader\\\\Csv\\\\CsvContiguousFilter\\:\\:\\$startRow \\(int\\) does not accept mixed\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousFilter.php - - - - message: "#^Cannot cast mixed to string\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousTest.php - - message: "#^Part \\$result \\(mixed\\) of encapsed string cannot be cast to string\\.$#" count: 2 @@ -8520,16 +8510,6 @@ parameters: count: 1 path: tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalFormattingDataBarXlsxTest.php - - - message: "#^Cannot cast mixed to string\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/Xlsx/Namespace.Issue2109bTest.php - - - - message: "#^Cannot cast mixed to string\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/Xlsx/Namespace.Openpyxl35Test.php - - message: "#^Part \\$result \\(mixed\\) of encapsed string cannot be cast to string\\.$#" count: 2 diff --git a/tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousFilter.php b/tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousFilter.php index eac37afc..31e60bdd 100644 --- a/tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousFilter.php +++ b/tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousFilter.php @@ -24,11 +24,8 @@ class CsvContiguousFilter implements IReadFilter /** * Set the list of rows that we want to read. - * - * @param mixed $startRow - * @param mixed $chunkSize */ - public function setRows($startRow, $chunkSize): void + public function setRows(int $startRow, int $chunkSize): void { $this->startRow = $startRow; $this->endRow = $startRow + $chunkSize; diff --git a/tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousTest.php b/tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousTest.php index ff095dba..291a29d0 100644 --- a/tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Csv/CsvContiguousTest.php @@ -57,11 +57,15 @@ class CsvContiguousTest extends TestCase private static function getCellValue(Spreadsheet $spreadsheet, string $sheetName, string $cellAddress): string { $sheet = $spreadsheet->getSheetByName($sheetName); - if ($sheet === null) { - return ''; + $result = ''; + if ($sheet !== null) { + $value = $sheet->getCell($cellAddress)->getValue(); + if (is_scalar($value) || (is_object($value) && method_exists($value, '__toString'))) { + $result = (string) $value; + } } - return (string) $sheet->getCell($cellAddress)->getValue(); + return $result; } public function testContiguous2(): void diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/Namespace.Issue2109bTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/NamespaceIssue2109bTest.php similarity index 94% rename from tests/PhpSpreadsheetTests/Reader/Xlsx/Namespace.Issue2109bTest.php rename to tests/PhpSpreadsheetTests/Reader/Xlsx/NamespaceIssue2109bTest.php index 98da11ba..4c1628fc 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xlsx/Namespace.Issue2109bTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/NamespaceIssue2109bTest.php @@ -60,8 +60,11 @@ class NamespaceIssue2109bTest extends \PHPUnit\Framework\TestCase private static function getCellValue(Worksheet $sheet, string $cell): string { $result = $sheet->getCell($cell)->getValue(); + if (is_scalar($result) || (is_object($result) && method_exists($result, '__toString'))) { + return (string) $result; + } - return (string) $result; + return ''; } public function testLoadXlsx(): void diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/Namespace.Openpyxl35Test.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/NamespaceOpenpyxl35Test.php similarity index 95% rename from tests/PhpSpreadsheetTests/Reader/Xlsx/Namespace.Openpyxl35Test.php rename to tests/PhpSpreadsheetTests/Reader/Xlsx/NamespaceOpenpyxl35Test.php index 16988a07..d57dc049 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xlsx/Namespace.Openpyxl35Test.php +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/NamespaceOpenpyxl35Test.php @@ -60,8 +60,11 @@ class NamespaceOpenpyxl35Test extends \PHPUnit\Framework\TestCase private static function getCellValue(Worksheet $sheet, string $cell): string { $result = $sheet->getCell($cell)->getValue(); + if (is_scalar($result) || (is_object($result) && method_exists($result, '__toString'))) { + return (string) $result; + } - return (string) $result; + return ''; } public function testLoadXlsx(): void