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.
This commit is contained in:
oleibman 2021-12-25 09:05:54 -08:00 committed by GitHub
parent f2b2f07ec3
commit 07271c83aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 29 deletions

View File

@ -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

View File

@ -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;

View File

@ -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

View File

@ -60,10 +60,13 @@ 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 '';
}
public function testLoadXlsx(): void
{
$reader = new Xlsx();

View File

@ -60,10 +60,13 @@ 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 '';
}
public function testLoadXlsx(): void
{
$reader = new Xlsx();