From ec773bbed9fc8f603798f144f3049b9319a88aae Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Sat, 15 Feb 2025 19:18:39 -0800 Subject: [PATCH] Phpstan Bleeding Edge Part 2 of Many This will be the biggest of these changes. It takes care of all of the remaining problems in tests. I will handle the problems in src more slowly. --- phpstan-baseline.neon | 395 ------------------ .../Calculation/CalculationLoggingTest.php | 6 +- .../Calculation/CalculationTest.php | 2 +- .../DefinedNameConfusedForCellTest.php | 5 +- .../Engine/FormattedNumberSlashTest.php | 11 +- .../Engine/FormattedNumberTest.php | 13 +- .../Functions/FormulaArguments.php | 2 +- .../PhpSpreadsheetTests/Cell/DataTypeTest.php | 1 - .../Cell/HyperlinkTest.php | 2 - .../Chart/DataSeriesValues2Test.php | 1 - .../Chart/DataSeriesValuesTest.php | 2 +- .../PhpSpreadsheetTests/Chart/LayoutTest.php | 2 +- .../PhpSpreadsheetTests/Chart/PR3163Test.php | 2 - .../Chart/PlotAreaTest.php | 2 +- tests/PhpSpreadsheetTests/CommentTest.php | 2 - tests/PhpSpreadsheetTests/DefinedNameTest.php | 1 - .../DocumentGeneratorTest.php | 1 - .../Functional/ColumnWidthTest.php | 5 +- tests/PhpSpreadsheetTests/Helper/HtmlTest.php | 3 +- .../PhpSpreadsheetTests/Helper/SampleTest.php | 11 +- tests/PhpSpreadsheetTests/IOFactoryTest.php | 10 +- .../Reader/Html/HtmlLoadStringTest.php | 4 +- .../Reader/Html/HtmlTest.php | 6 - .../Reader/Ods/OdsPropertiesTest.php | 2 - .../Reader/Ods/OdsTest.php | 25 +- .../Reader/Security/XmlScannerTest.php | 1 - .../Reader/Xlsx/AbsolutePathTest.php | 1 - .../ConditionalFormattingDataBarXlsxTest.php | 9 - .../Reader/Xlsx/PropertiesTest.php | 2 - .../Reader/Xlsx/VmlTest.php | 1 - .../Reader/Xlsx/XlsxTest.php | 3 +- .../ReferenceHelper2Test.php | 3 +- tests/PhpSpreadsheetTests/RichTextTest.php | 1 - tests/PhpSpreadsheetTests/SettingsTest.php | 1 - tests/PhpSpreadsheetTests/Shared/DateTest.php | 12 +- .../Shared/ExactFontTest.php | 54 ++- .../Wizard/BlankWizardTest.php | 2 - .../Wizard/DuplicatesWizardTest.php | 2 - .../Wizard/ErrorWizardTest.php | 2 - .../Wizard/TextValueWizardTest.php | 5 - .../Worksheet/AutoFilter/AutoFilterTest.php | 34 +- .../Worksheet/AutoFilter/ColumnTest.php | 8 +- .../Worksheet/ByColumnAndRowTest.php | 4 - .../ByColumnAndRowUndeprecatedTest.php | 4 - .../Worksheet/ColumnCellIterator2Test.php | 23 +- .../Worksheet/ColumnCellIteratorTest.php | 12 +- .../Worksheet/ColumnDimensionTest.php | 1 - .../Worksheet/ColumnIteratorTest.php | 3 - .../Worksheet/ColumnTest.php | 7 +- .../Worksheet/IteratorTest.php | 2 - .../Worksheet/MemoryDrawingTest.php | 4 - .../Worksheet/RowCellIterator2Test.php | 23 +- .../Worksheet/RowCellIteratorTest.php | 5 - .../Worksheet/RowDimensionTest.php | 1 - .../Worksheet/RowIteratorTest.php | 3 - .../PhpSpreadsheetTests/Worksheet/RowTest.php | 7 +- .../Worksheet/Table/ColumnTest.php | 5 - .../Worksheet/Table/TableStyleTest.php | 5 - .../Worksheet/Table/TableTest.php | 41 +- .../Worksheet/Worksheet2Test.php | 3 +- 60 files changed, 132 insertions(+), 678 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index fd84f8821..f51637c68 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -504,398 +504,3 @@ parameters: message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\ConditionalFormatValueObject and null will always evaluate to true\\.$#" count: 2 path: src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array\\ will always evaluate to true\\.$#" - count: 4 - path: tests/PhpSpreadsheetTests/Calculation/CalculationLoggingTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\) with true will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Calculation/CalculationTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\) with true will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Calculation/DefinedNameConfusedForCellTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\) with float and string will always evaluate to false\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberSlashTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\) with float and string will always evaluate to false\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberTest.php - - - - message: "#^Parameter \\#1 \\$callback of function array_map expects \\(callable\\(mixed\\)\\: mixed\\)\\|null, array\\{'PhpOffice\\\\\\\\PhpSpreadsheetTests\\\\\\\\Calculation\\\\\\\\Functions\\\\\\\\FormulaArguments', 'stringify'\\} given\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Calculation/Functions/FormulaArguments.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array\\ will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Cell/DataTypeTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Cell\\\\\\\\Hyperlink' and PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Hyperlink will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Cell/HyperlinkTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\DataSeries will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Chart/DataSeriesValues2Test.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Chart\\\\\\\\DataSeriesValues' and PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\DataSeriesValues will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Chart\\\\\\\\Layout' and PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Layout will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Chart/LayoutTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\Axis will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Chart/PR3163Test.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Chart\\\\PlotArea will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Chart/PlotAreaTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\RichText\\\\\\\\RichText' and PhpOffice\\\\PhpSpreadsheet\\\\RichText\\\\RichText will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/CommentTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Style\\\\\\\\Color' and PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Color will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/CommentTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\NamedRange' and PhpOffice\\\\PhpSpreadsheet\\\\NamedRange will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/DefinedNameTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotEmpty\\(\\) with 'docs/references/' will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/DocumentGeneratorTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\ColumnDimension' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php - - - - message: "#^PHPDoc tag @var with type callable\\(\\)\\: mixed is not subtype of native type array\\{'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Helper\\\\\\\\Html', 'breakTag'\\}\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Helper/HtmlTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\) with true will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Helper/SampleTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Spreadsheet' and PhpOffice\\\\PhpSpreadsheet\\\\Spreadsheet will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/IOFactoryTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\) with true will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension will always evaluate to true\\.$#" - count: 3 - path: tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension will always evaluate to true\\.$#" - count: 3 - path: tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array\\ will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Reader/Ods/OdsPropertiesTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice…' and PhpOffice\\\\PhpSpreadsheet\\\\Spreadsheet will always evaluate to true\\.$#" - count: 3 - path: tests/PhpSpreadsheetTests/Reader/Ods/OdsTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice…' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet will always evaluate to true\\.$#" - count: 6 - path: tests/PhpSpreadsheetTests/Reader/Ods/OdsTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Reader\\\\\\\\Security\\\\\\\\XmlScanner' and PhpOffice\\\\PhpSpreadsheet\\\\Reader\\\\Security\\\\XmlScanner will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/Security/XmlScannerTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/Xlsx/AbsolutePathTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\ConditionalDataBar will always evaluate to true\\.$#" - count: 5 - path: tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalFormattingDataBarXlsxTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\ConditionalFormattingRuleExtension will always evaluate to true\\.$#" - count: 4 - path: tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalFormattingDataBarXlsxTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array\\ will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Reader/Xlsx/PropertiesTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\) with true will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/Xlsx/VmlTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Style\\\\\\\\Style' and PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Style will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/Xlsx/XlsxTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\AutoFilter' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Reader/Xlsx/XlsxTest.php - - - - message: "#^Expression \"clone \\$referenceHelper\" on a separate line does not do anything\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/ReferenceHelper2Test.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\Font will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/RichTextTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with Psr\\\\SimpleCache\\\\CacheInterface will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/SettingsTest.php - - - - message: "#^Call to function is_numeric\\(\\) with float\\|int will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Shared/DateTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell will always evaluate to true\\.$#" - count: 4 - path: tests/PhpSpreadsheetTests/Shared/DateTest.php - - - - message: "#^Strict comparison using \\!\\=\\= between null and PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell will always evaluate to true\\.$#" - count: 3 - path: tests/PhpSpreadsheetTests/Shared/DateTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\) with true will always evaluate to true\\.$#" - count: 6 - path: tests/PhpSpreadsheetTests/Shared/ExactFontTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Style\\\\\\\\ConditionalFormatting\\\\\\\\Wizard\\\\\\\\Blanks' and PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\Wizard\\\\Blanks will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/BlankWizardTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Style\\\\\\\\ConditionalFormatting\\\\\\\\Wizard\\\\\\\\Duplicates' and PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\Wizard\\\\Duplicates will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/DuplicatesWizardTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Style\\\\\\\\ConditionalFormatting\\\\\\\\Wizard\\\\\\\\Errors' and PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\Wizard\\\\Errors will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/ErrorWizardTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Style\\\\\\\\ConditionalFormatting\\\\\\\\Wizard\\\\\\\\TextValue' and PhpOffice\\\\PhpSpreadsheet\\\\Style\\\\ConditionalFormatting\\\\Wizard\\\\TextValue will always evaluate to true\\.$#" - count: 5 - path: tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/TextValueWizardTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\AutoFilter' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter will always evaluate to true\\.$#" - count: 8 - path: tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\AutoFilter\\\\\\\\Column' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter\\\\Column will always evaluate to true\\.$#" - count: 10 - path: tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Worksheet' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array\\ will always evaluate to true\\.$#" - count: 8 - path: tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\AutoFilter\\\\\\\\Column' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter\\\\Column will always evaluate to true\\.$#" - count: 6 - path: tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\AutoFilter\\\\\\\\Column\\\\\\\\Rule' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter\\\\Column\\\\Rule will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Comment' and PhpOffice\\\\PhpSpreadsheet\\\\Comment will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\AutoFilter' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Comment' and PhpOffice\\\\PhpSpreadsheet\\\\Comment will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowUndeprecatedTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\AutoFilter' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\AutoFilter will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowUndeprecatedTest.php - - - - message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell and null will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/ColumnCellIterator2Test.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Cell\\\\\\\\Cell' and PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\ColumnDimension' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/ColumnDimensionTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Column' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Column will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Column' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Column will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/ColumnTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\ColumnCellIterator' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnCellIterator will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/ColumnTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Worksheet' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/IteratorTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'GdImage' and GdImage will always evaluate to true\\.$#" - count: 3 - path: tests/PhpSpreadsheetTests/Worksheet/MemoryDrawingTest.php - - - - message: "#^Strict comparison using \\!\\=\\= between PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell and null will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/RowCellIterator2Test.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Cell\\\\\\\\Cell' and PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotNull\\(\\) with PhpOffice\\\\PhpSpreadsheet\\\\Cell\\\\Cell will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\RowDimension' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/RowDimensionTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Row' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Row will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Row' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Row will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/RowTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\RowCellIterator' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowCellIterator will always evaluate to true\\.$#" - count: 2 - path: tests/PhpSpreadsheetTests/Worksheet/RowTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Table\\\\\\\\Column' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Table\\\\Column will always evaluate to true\\.$#" - count: 5 - path: tests/PhpSpreadsheetTests/Worksheet/Table/ColumnTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Table\\\\\\\\TableStyle' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Table\\\\TableStyle will always evaluate to true\\.$#" - count: 5 - path: tests/PhpSpreadsheetTests/Worksheet/Table/TableStyleTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Table' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Table will always evaluate to true\\.$#" - count: 11 - path: tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Table\\\\\\\\Column' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Table\\\\Column will always evaluate to true\\.$#" - count: 10 - path: tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'PhpOffice\\\\\\\\PhpSpreadsheet\\\\\\\\Worksheet\\\\\\\\Worksheet' and PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\Worksheet will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertIsArray\\(\\) with array\\ will always evaluate to true\\.$#" - count: 8 - path: tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php - - - - message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEmpty\\(\\) with null will always evaluate to true\\.$#" - count: 1 - path: tests/PhpSpreadsheetTests/Worksheet/Worksheet2Test.php diff --git a/tests/PhpSpreadsheetTests/Calculation/CalculationLoggingTest.php b/tests/PhpSpreadsheetTests/Calculation/CalculationLoggingTest.php index 8e90644c7..04fcdc4c7 100644 --- a/tests/PhpSpreadsheetTests/Calculation/CalculationLoggingTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/CalculationLoggingTest.php @@ -31,7 +31,6 @@ class CalculationLoggingTest extends TestCase self::assertEquals(6.7, $cell->getCalculatedValue()); $log = $debugLog->getLog(); - self::assertIsArray($log); $entries = count($log); self::assertGreaterThan(0, $entries); @@ -71,7 +70,6 @@ class CalculationLoggingTest extends TestCase $log = $debugLog->getLog(); - self::assertIsArray($log); $entries = count($log); self::assertGreaterThan(0, $entries); @@ -114,14 +112,12 @@ class CalculationLoggingTest extends TestCase self::assertEquals(-0.75, $cell->getCalculatedValue()); $log = $debugLog->getLog(); - self::assertIsArray($log); $entries = count($log); self::assertGreaterThan(0, $entries); $debugLog->clearLog(); $log = $debugLog->getLog(); - self::assertIsArray($log); - self::assertEmpty($log); + self::assertSame([], $log); } } diff --git a/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php b/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php index 3a4e67aef..806a5fd90 100644 --- a/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php @@ -343,7 +343,7 @@ class CalculationTest extends TestCase // this used to raise a parser error, we keep it even though we don't // test the output $calculation->parseFormula($formula); - self::assertTrue(true); + self::assertSame(1, $calculation->cyclicFormulaCount); } public function testBranchPruningFormulaParsingInequalitiesConditionsCase(): void diff --git a/tests/PhpSpreadsheetTests/Calculation/DefinedNameConfusedForCellTest.php b/tests/PhpSpreadsheetTests/Calculation/DefinedNameConfusedForCellTest.php index 703996d9a..68eae9556 100644 --- a/tests/PhpSpreadsheetTests/Calculation/DefinedNameConfusedForCellTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/DefinedNameConfusedForCellTest.php @@ -17,12 +17,13 @@ class DefinedNameConfusedForCellTest extends TestCase $obj = new Spreadsheet(); $sheet0 = $obj->setActiveSheetIndex(0); $sheet0->setCellValue('A1', 2); - $obj->addNamedRange(new NamedRange('A1A', $sheet0, 'A1')); + $obj->addNamedRange(new NamedRange('A1A', $sheet0, '$A$1')); $sheet0->setCellValue('B1', '=2*A1A'); $writer = IOFactory::createWriter($obj, 'Xlsx'); $filename = File::temporaryFilename(); $writer->save($filename); - self::assertTrue(true); unlink($filename); + self::assertSame(4, $obj->getActiveSheet()->getCell('B1')->getCalculatedValue()); + $obj->disconnectWorksheets(); } } diff --git a/tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberSlashTest.php b/tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberSlashTest.php index d9dd25142..32c3c48fb 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberSlashTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberSlashTest.php @@ -6,6 +6,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Engine; use PhpOffice\PhpSpreadsheet\Calculation\Engine\FormattedNumber; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class FormattedNumberSlashTest extends TestCase @@ -17,14 +18,16 @@ class FormattedNumberSlashTest extends TestCase StringHelper::setThousandsSeparator(null); } - #[\PHPUnit\Framework\Attributes\DataProvider('providerNumbers')] + #[DataProvider('providerNumbers')] public function testNumber(float $expected, string $value, string $thousandsSeparator = ',', string $decimalSeparator = '.'): void { StringHelper::setThousandsSeparator($thousandsSeparator); StringHelper::setDecimalSeparator($decimalSeparator); $result = FormattedNumber::convertToNumberIfFormatted($value); self::assertTrue($result); - self::assertSame($expected, $value); + // Call by ref convert... changed type from string to float. + // Phpstan can't figure that out. + self::assertSame($expected, $value); // @phpstan-ignore-line } public static function providerNumbers(): array @@ -36,7 +39,7 @@ class FormattedNumberSlashTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerPercentages')] + #[DataProvider('providerPercentages')] public function testPercentage(string $expected, string $value, string $thousandsSeparator = ',', string $decimalSeparator = '.'): void { $originalValue = $value; @@ -57,7 +60,7 @@ class FormattedNumberSlashTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCurrencies')] + #[DataProvider('providerCurrencies')] public function testCurrencies(string $expected, string $value, string $thousandsSeparator = ',', string $decimalSeparator = '.', ?string $currencyCode = null): void { $originalValue = $value; diff --git a/tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberTest.php b/tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberTest.php index 3410a04c6..41a08019d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberTest.php @@ -6,15 +6,18 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Engine; use PhpOffice\PhpSpreadsheet\Calculation\Engine\FormattedNumber; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class FormattedNumberTest extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('providerNumbers')] + #[DataProvider('providerNumbers')] public function testNumber(float $expected, string $value): void { FormattedNumber::convertToNumberIfFormatted($value); - self::assertSame($expected, $value); + // Call by ref convert... changed type from string to float. + // Phpstan can't figure that out. + self::assertSame($expected, $value); // @phpstan-ignore-line } public static function providerNumbers(): array @@ -29,7 +32,7 @@ class FormattedNumberTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerFractions')] + #[DataProvider('providerFractions')] public function testFraction(string $expected, string $value): void { $originalValue = $value; @@ -56,7 +59,7 @@ class FormattedNumberTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerPercentages')] + #[DataProvider('providerPercentages')] public function testPercentage(string $expected, string $value): void { $originalValue = $value; @@ -183,7 +186,7 @@ class FormattedNumberTest extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCurrencies')] + #[DataProvider('providerCurrencies')] public function testCurrencies(string $expected, string $value): void { $originalValue = $value; diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/FormulaArguments.php b/tests/PhpSpreadsheetTests/Calculation/Functions/FormulaArguments.php index 0454c0f14..423e330bc 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/FormulaArguments.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/FormulaArguments.php @@ -92,7 +92,7 @@ class FormulaArguments implements Stringable public function __toString(): string { $args = array_map( - [self::class, 'stringify'], + self::stringify(...), $this->args ); diff --git a/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php b/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php index 974297c4c..9554e88e6 100644 --- a/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php +++ b/tests/PhpSpreadsheetTests/Cell/DataTypeTest.php @@ -13,7 +13,6 @@ class DataTypeTest extends TestCase public function testGetErrorCodes(): void { $result = DataType::getErrorCodes(); - self::assertIsArray($result); self::assertGreaterThan(0, count($result)); self::assertArrayHasKey('#NULL!', $result); } diff --git a/tests/PhpSpreadsheetTests/Cell/HyperlinkTest.php b/tests/PhpSpreadsheetTests/Cell/HyperlinkTest.php index 68d43e418..32f21047f 100644 --- a/tests/PhpSpreadsheetTests/Cell/HyperlinkTest.php +++ b/tests/PhpSpreadsheetTests/Cell/HyperlinkTest.php @@ -26,7 +26,6 @@ class HyperlinkTest extends TestCase $testInstance = new Hyperlink($initialUrlValue); $result = $testInstance->setUrl($newUrlValue); - self::assertInstanceOf(Hyperlink::class, $result); $result = $testInstance->getUrl(); self::assertEquals($newUrlValue, $result); @@ -49,7 +48,6 @@ class HyperlinkTest extends TestCase $testInstance = new Hyperlink('', $initialTooltipValue); $result = $testInstance->setTooltip($newTooltipValue); - self::assertInstanceOf(Hyperlink::class, $result); $result = $testInstance->getTooltip(); self::assertEquals($newTooltipValue, $result); diff --git a/tests/PhpSpreadsheetTests/Chart/DataSeriesValues2Test.php b/tests/PhpSpreadsheetTests/Chart/DataSeriesValues2Test.php index a525322b2..34dfa4319 100644 --- a/tests/PhpSpreadsheetTests/Chart/DataSeriesValues2Test.php +++ b/tests/PhpSpreadsheetTests/Chart/DataSeriesValues2Test.php @@ -145,7 +145,6 @@ class DataSeriesValues2Test extends AbstractFunctional $plotArea2 = $chart2->getPlotArea(); self::assertNotNull($plotArea2); $plotGroup2 = $plotArea2->getPlotGroup()[0]; - self::assertNotNull($plotGroup2); $plotValues2 = $plotGroup2->getPlotValues(); self::assertCount(3, $plotValues2); self::assertSame([15.0, 73.0, 61.0, 32.0], $plotValues2[1]->getDataValues()); diff --git a/tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php b/tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php index 58783bc1d..05f81224a 100644 --- a/tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php +++ b/tests/PhpSpreadsheetTests/Chart/DataSeriesValuesTest.php @@ -22,7 +22,7 @@ class DataSeriesValuesTest extends TestCase foreach ($dataTypeValues as $dataTypeValue) { $result = $testInstance->setDataType($dataTypeValue); - self::assertInstanceOf(DataSeriesValues::class, $result); + self::assertSame($dataTypeValue, $result->getDataType()); } } diff --git a/tests/PhpSpreadsheetTests/Chart/LayoutTest.php b/tests/PhpSpreadsheetTests/Chart/LayoutTest.php index e54f1646b..3f6b88fdb 100644 --- a/tests/PhpSpreadsheetTests/Chart/LayoutTest.php +++ b/tests/PhpSpreadsheetTests/Chart/LayoutTest.php @@ -17,7 +17,7 @@ class LayoutTest extends TestCase $testInstance = new Layout(); $result = $testInstance->setLayoutTarget($LayoutTargetValue); - self::assertInstanceOf(Layout::class, $result); + self::assertSame('String', $result->getLayoutTarget()); } public function testGetLayoutTarget(): void diff --git a/tests/PhpSpreadsheetTests/Chart/PR3163Test.php b/tests/PhpSpreadsheetTests/Chart/PR3163Test.php index bfce4ca8d..7f24e53d0 100644 --- a/tests/PhpSpreadsheetTests/Chart/PR3163Test.php +++ b/tests/PhpSpreadsheetTests/Chart/PR3163Test.php @@ -143,12 +143,10 @@ class PR3163Test extends AbstractFunctional self::assertNotNull($chart2); $xAxis2 = $chart2->getChartAxisX(); - self::assertNotNull($xAxis2); $lineColorX2 = $xAxis2->getLineColorProperty('value'); self::assertSame($lineColorX2, 'FF0000'); $yAxis2 = $chart2->getChartAxisY(); - self::assertNotNull($yAxis2); $lineColorY2 = $yAxis2->getLineColorProperty('value'); self::assertSame($lineColorY2, '00FF00'); diff --git a/tests/PhpSpreadsheetTests/Chart/PlotAreaTest.php b/tests/PhpSpreadsheetTests/Chart/PlotAreaTest.php index 819e41cec..b0cca1234 100644 --- a/tests/PhpSpreadsheetTests/Chart/PlotAreaTest.php +++ b/tests/PhpSpreadsheetTests/Chart/PlotAreaTest.php @@ -35,7 +35,7 @@ class PlotAreaTest extends TestCase 'chart1', // name plotArea: $plotArea, ); - self::assertNotNull($chart->getPlotAreaOrThrow()); + self::assertNotNull($chart->getPlotArea()); } public function testNoPlotArea(): void diff --git a/tests/PhpSpreadsheetTests/CommentTest.php b/tests/PhpSpreadsheetTests/CommentTest.php index 0993305b4..4b2c6d88d 100644 --- a/tests/PhpSpreadsheetTests/CommentTest.php +++ b/tests/PhpSpreadsheetTests/CommentTest.php @@ -22,9 +22,7 @@ class CommentTest extends TestCase self::assertEquals('59.25pt', $comment->getMarginLeft()); self::assertEquals('1.5pt', $comment->getMarginTop()); self::assertEquals('55.5pt', $comment->getHeight()); - self::assertInstanceOf(Color::class, $comment->getFillColor()); self::assertEquals('FFFFFFE1', $comment->getFillColor()->getARGB()); - self::assertInstanceOf(RichText::class, $comment->getText()); self::assertEquals(Alignment::HORIZONTAL_GENERAL, $comment->getAlignment()); self::assertFalse($comment->getVisible()); } diff --git a/tests/PhpSpreadsheetTests/DefinedNameTest.php b/tests/PhpSpreadsheetTests/DefinedNameTest.php index 34fac61d9..361cebd76 100644 --- a/tests/PhpSpreadsheetTests/DefinedNameTest.php +++ b/tests/PhpSpreadsheetTests/DefinedNameTest.php @@ -144,7 +144,6 @@ class DefinedNameTest extends TestCase DefinedName::createInstance('xyz', $this->spreadsheet->getActiveSheet(), 'A1') ); - /** @var NamedRange $namedRange */ $namedRange = $this->spreadsheet->getDefinedName('XYZ'); self::assertInstanceOf(NamedRange::class, $namedRange); self::assertEquals('A1', $namedRange->getRange()); diff --git a/tests/PhpSpreadsheetTests/DocumentGeneratorTest.php b/tests/PhpSpreadsheetTests/DocumentGeneratorTest.php index 1ce621f74..4dc326370 100644 --- a/tests/PhpSpreadsheetTests/DocumentGeneratorTest.php +++ b/tests/PhpSpreadsheetTests/DocumentGeneratorTest.php @@ -169,7 +169,6 @@ class DocumentGeneratorTest extends TestCase self::markTestSkipped('Not run because prior test failed'); } $directory = 'docs/references/'; - self::assertNotEmpty($directory); $phpSpreadsheetFunctions = Calculation::getFunctions(); ksort($phpSpreadsheetFunctions); diff --git a/tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php b/tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php index 0f7e5f7e4..8a8d61d3d 100644 --- a/tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php +++ b/tests/PhpSpreadsheetTests/Functional/ColumnWidthTest.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Functional; use PhpOffice\PhpSpreadsheet\Spreadsheet; -use PhpOffice\PhpSpreadsheet\Worksheet\ColumnDimension; +use PHPUnit\Framework\Attributes\DataProvider; class ColumnWidthTest extends AbstractFunctional { @@ -16,7 +16,7 @@ class ColumnWidthTest extends AbstractFunctional ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerFormats')] + #[DataProvider('providerFormats')] public function testReadColumnWidth(string $format): void { // create new sheet with column width @@ -37,7 +37,6 @@ class ColumnWidthTest extends AbstractFunctional self::assertArrayHasKey('A', $columnDimensions); $column = array_shift($columnDimensions); - self::assertInstanceOf(ColumnDimension::class, $column); self::assertEquals(20, $column->getWidth()); } } diff --git a/tests/PhpSpreadsheetTests/Helper/HtmlTest.php b/tests/PhpSpreadsheetTests/Helper/HtmlTest.php index 6779fb9b5..efd44a86e 100644 --- a/tests/PhpSpreadsheetTests/Helper/HtmlTest.php +++ b/tests/PhpSpreadsheetTests/Helper/HtmlTest.php @@ -34,8 +34,7 @@ class HtmlTest extends TestCase public function testLiTag(): void { $html = new Html(); - /** @var callable */ - $htmlBreakTag = [Html::class, 'breakTag']; + $htmlBreakTag = $html->breakTag(...); $html->addStartTagCallback('li', function (DOMElement $tag, Html $object): void { $object->stringData .= "\u{00A0}\u{2022} \u{00A0}"; }); diff --git a/tests/PhpSpreadsheetTests/Helper/SampleTest.php b/tests/PhpSpreadsheetTests/Helper/SampleTest.php index e8c79bed4..3759ff17a 100644 --- a/tests/PhpSpreadsheetTests/Helper/SampleTest.php +++ b/tests/PhpSpreadsheetTests/Helper/SampleTest.php @@ -5,20 +5,23 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Helper; use PhpOffice\PhpSpreadsheet\Helper\Sample; +use PHPUnit\Framework\Attributes; use PHPUnit\Framework\TestCase; class SampleTest extends TestCase { - #[\PHPUnit\Framework\Attributes\RunInSeparateProcess] - #[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)] - #[\PHPUnit\Framework\Attributes\DataProvider('providerSample')] + private static bool $alwaysTrue = true; + + #[Attributes\RunInSeparateProcess] + #[Attributes\PreserveGlobalState(false)] + #[Attributes\DataProvider('providerSample')] public function testSample(string $sample): void { ob_start(); require $sample; ob_end_clean(); - self::assertTrue(true); + self::assertTrue(self::$alwaysTrue); } public static function providerSample(): array diff --git a/tests/PhpSpreadsheetTests/IOFactoryTest.php b/tests/PhpSpreadsheetTests/IOFactoryTest.php index 4693a2f99..7fb1d79e9 100644 --- a/tests/PhpSpreadsheetTests/IOFactoryTest.php +++ b/tests/PhpSpreadsheetTests/IOFactoryTest.php @@ -9,11 +9,12 @@ use PhpOffice\PhpSpreadsheet\Reader; use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class IOFactoryTest extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('providerCreateWriter')] + #[DataProvider('providerCreateWriter')] public function testCreateWriter(string $name, string $expected): void { $spreadsheet = new Spreadsheet(); @@ -43,7 +44,7 @@ class IOFactoryTest extends TestCase self::assertInstanceOf(Writer\Pdf\Mpdf::class, $actual); } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCreateReader')] + #[DataProvider('providerCreateReader')] public function testCreateReader(string $name, string $expected): void { $actual = IOFactory::createReader($name); @@ -71,15 +72,14 @@ class IOFactoryTest extends TestCase self::assertInstanceOf(Reader\Html::class, $actual); } - #[\PHPUnit\Framework\Attributes\DataProvider('providerIdentify')] + #[DataProvider('providerIdentify')] public function testIdentifyCreateLoad(string $file, string $expectedName, string $expectedClass): void { $actual = IOFactory::identify($file); self::assertSame($expectedName, $actual); $actual = IOFactory::createReaderForFile($file); self::assertSame($expectedClass, $actual::class); - $actual = IOFactory::load($file); - self::assertInstanceOf(Spreadsheet::class, $actual); + IOFactory::load($file); } public static function providerIdentify(): array diff --git a/tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php b/tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php index 9f85c9567..ba059cf66 100644 --- a/tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php @@ -10,6 +10,8 @@ use PHPUnit\Framework\TestCase; class HtmlLoadStringTest extends TestCase { + private static bool $alwaysTrue = true; + public function testCanLoadFromString(): void { $html = ' @@ -48,7 +50,7 @@ class HtmlLoadStringTest extends TestCase (new Html())->loadFromString($html); } else { // The meat of this test runs in HtmlPhpunit10Test - self::assertTrue(true); + self::assertTrue(self::$alwaysTrue); } } diff --git a/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php b/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php index 8d2341144..d15fc9583 100644 --- a/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php @@ -153,15 +153,12 @@ class HtmlTest extends TestCase $firstSheet = $spreadsheet->getSheet(0); $dimension = $firstSheet->getColumnDimension('A'); - self::assertNotNull($dimension); self::assertEquals(50, $dimension->getWidth()); $dimension = $firstSheet->getColumnDimension('B'); - self::assertNotNull($dimension); self::assertEquals(100, $dimension->getWidth('px')); $dimension = $firstSheet->getColumnDimension('C'); - self::assertNotNull($dimension); self::assertEquals(50, $dimension->getWidth('px')); $spreadsheet->disconnectWorksheets(); } @@ -184,15 +181,12 @@ class HtmlTest extends TestCase $firstSheet = $spreadsheet->getSheet(0); $dimension = $firstSheet->getRowDimension(1); - self::assertNotNull($dimension); self::assertEquals(50, $dimension->getRowHeight()); $dimension = $firstSheet->getRowDimension(2); - self::assertNotNull($dimension); self::assertEquals(100, $dimension->getRowHeight('px')); $dimension = $firstSheet->getRowDimension(3); - self::assertNotNull($dimension); self::assertEquals(50, $dimension->getRowHeight('px')); $spreadsheet->disconnectWorksheets(); } diff --git a/tests/PhpSpreadsheetTests/Reader/Ods/OdsPropertiesTest.php b/tests/PhpSpreadsheetTests/Reader/Ods/OdsPropertiesTest.php index 89c8d8d84..c6d6d84fd 100644 --- a/tests/PhpSpreadsheetTests/Reader/Ods/OdsPropertiesTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Ods/OdsPropertiesTest.php @@ -51,7 +51,6 @@ class OdsPropertiesTest extends AbstractFunctional // Custom Properties $customProperties = $properties->getCustomProperties(); - self::assertIsArray($customProperties); $customProperties = array_flip($customProperties); self::assertArrayHasKey('TestDate', $customProperties); @@ -97,7 +96,6 @@ class OdsPropertiesTest extends AbstractFunctional // Custom Properties $customProperties = $properties->getCustomProperties(); - self::assertIsArray($customProperties); $customProperties = array_flip($customProperties); self::assertArrayHasKey('TestDate', $customProperties); diff --git a/tests/PhpSpreadsheetTests/Reader/Ods/OdsTest.php b/tests/PhpSpreadsheetTests/Reader/Ods/OdsTest.php index 840646d7f..3a3dd45c4 100644 --- a/tests/PhpSpreadsheetTests/Reader/Ods/OdsTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Ods/OdsTest.php @@ -53,16 +53,9 @@ class OdsTest extends TestCase public function testLoadWorksheets(): void { $spreadsheet = $this->loadDataFile(); - - self::assertInstanceOf('PhpOffice\PhpSpreadsheet\Spreadsheet', $spreadsheet); - self::assertEquals(2, $spreadsheet->getSheetCount()); - $firstSheet = $spreadsheet->getSheet(0); - self::assertInstanceOf('PhpOffice\PhpSpreadsheet\Worksheet\Worksheet', $firstSheet); - $secondSheet = $spreadsheet->getSheet(1); - self::assertInstanceOf('PhpOffice\PhpSpreadsheet\Worksheet\Worksheet', $secondSheet); self::assertEquals('Sheet1', $spreadsheet->getSheet(0)->getTitle()); self::assertEquals('Second Sheet', $spreadsheet->getSheet(1)->getTitle()); $spreadsheet->disconnectWorksheets(); @@ -106,18 +99,9 @@ class OdsTest extends TestCase public function testLoadBadFile(): void { $this->expectException(ReaderException::class); + $this->expectExceptionMessage('Could not find zip member'); $reader = new Ods(); - $spreadsheet = $reader->load(__FILE__); - - self::assertInstanceOf('PhpOffice\PhpSpreadsheet\Spreadsheet', $spreadsheet); - - self::assertEquals(2, $spreadsheet->getSheetCount()); - - $firstSheet = $spreadsheet->getSheet(0); - self::assertInstanceOf('PhpOffice\PhpSpreadsheet\Worksheet\Worksheet', $firstSheet); - - $secondSheet = $spreadsheet->getSheet(1); - self::assertInstanceOf('PhpOffice\PhpSpreadsheet\Worksheet\Worksheet', $secondSheet); + $reader->load(__FILE__); } public function testLoadCorruptFile(): void @@ -127,15 +111,12 @@ class OdsTest extends TestCase $reader = new Ods(); $spreadsheet = $reader->load($filename); - self::assertInstanceOf('PhpOffice\PhpSpreadsheet\Spreadsheet', $spreadsheet); - self::assertEquals(2, $spreadsheet->getSheetCount()); $firstSheet = $spreadsheet->getSheet(0); - self::assertInstanceOf('PhpOffice\PhpSpreadsheet\Worksheet\Worksheet', $firstSheet); $secondSheet = $spreadsheet->getSheet(1); - self::assertInstanceOf('PhpOffice\PhpSpreadsheet\Worksheet\Worksheet', $secondSheet); + self::assertNotSame($firstSheet, $secondSheet); } public function testReadValueAndComments(): void diff --git a/tests/PhpSpreadsheetTests/Reader/Security/XmlScannerTest.php b/tests/PhpSpreadsheetTests/Reader/Security/XmlScannerTest.php index 50b72d0c3..f19a5e80e 100644 --- a/tests/PhpSpreadsheetTests/Reader/Security/XmlScannerTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Security/XmlScannerTest.php @@ -69,7 +69,6 @@ class XmlScannerTest extends TestCase $scanner = $fileReader->getSecurityScanner(); // Must return an object... - self::assertIsObject($scanner); // ... of the correct type self::assertInstanceOf(XmlScanner::class, $scanner); } diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/AbsolutePathTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/AbsolutePathTest.php index a99eab803..a46c25681 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xlsx/AbsolutePathTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/AbsolutePathTest.php @@ -15,7 +15,6 @@ class AbsolutePathTest extends TestCase $reader = new Xlsx(); $result = $reader->listWorksheetInfo($xlsxFile); - self::assertIsArray($result); self::assertEquals(3, $result[0]['totalRows']); } } diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalFormattingDataBarXlsxTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalFormattingDataBarXlsxTest.php index 6a0ac7def..e5c1211a1 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalFormattingDataBarXlsxTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/ConditionalFormattingDataBarXlsxTest.php @@ -87,7 +87,6 @@ class ConditionalFormattingDataBarXlsxTest extends TestCase self::assertNotEmpty($conditionalRule->getDataBar()); $dataBar = $conditionalRule->getDataBar(); - self::assertNotNull($dataBar); self::assertNotNull($dataBar->getMinimumConditionalFormatValueObject()); self::assertNotNull($dataBar->getMaximumConditionalFormatValueObject()); self::assertEquals('min', $dataBar->getMinimumConditionalFormatValueObject()->getType()); @@ -110,7 +109,6 @@ class ConditionalFormattingDataBarXlsxTest extends TestCase self::assertNotEmpty($dataBar); self::assertEquals(Conditional::CONDITION_DATABAR, $conditionalRule->getConditionType()); - self::assertNotNull($dataBar); self::assertNotNull($dataBar->getMinimumConditionalFormatValueObject()); self::assertNotNull($dataBar->getMaximumConditionalFormatValueObject()); self::assertEquals('min', $dataBar->getMinimumConditionalFormatValueObject()->getType()); @@ -120,7 +118,6 @@ class ConditionalFormattingDataBarXlsxTest extends TestCase self::assertNotEmpty($dataBar->getConditionalFormattingRuleExt()); //ext $rule1ext = $dataBar->getConditionalFormattingRuleExt(); - self::assertNotNull($rule1ext); self::assertEquals('{72C64AE0-5CD9-164F-83D1-AB720F263E79}', $rule1ext->getId()); self::assertEquals('dataBar', $rule1ext->getCfRule()); self::assertEquals('A3:A23', $rule1ext->getSqref()); @@ -167,7 +164,6 @@ class ConditionalFormattingDataBarXlsxTest extends TestCase self::assertNotEmpty($dataBar); self::assertEquals(Conditional::CONDITION_DATABAR, $conditionalRule->getConditionType()); - self::assertNotNull($dataBar); self::assertNotNull($dataBar->getMinimumConditionalFormatValueObject()); self::assertNotNull($dataBar->getMaximumConditionalFormatValueObject()); self::assertEquals('num', $dataBar->getMinimumConditionalFormatValueObject()->getType()); @@ -178,7 +174,6 @@ class ConditionalFormattingDataBarXlsxTest extends TestCase self::assertNotEmpty($dataBar->getConditionalFormattingRuleExt()); //ext $rule1ext = $dataBar->getConditionalFormattingRuleExt(); - self::assertNotNull($rule1ext); self::assertEquals('{98904F60-57F0-DF47-B480-691B20D325E3}', $rule1ext->getId()); self::assertEquals('dataBar', $rule1ext->getCfRule()); self::assertEquals('B3:B23', $rule1ext->getSqref()); @@ -227,7 +222,6 @@ class ConditionalFormattingDataBarXlsxTest extends TestCase self::assertNotEmpty($dataBar); self::assertEquals(Conditional::CONDITION_DATABAR, $conditionalRule->getConditionType()); - self::assertNotNull($dataBar); self::assertNotNull($dataBar->getMinimumConditionalFormatValueObject()); self::assertNotNull($dataBar->getMaximumConditionalFormatValueObject()); self::assertEquals('min', $dataBar->getMinimumConditionalFormatValueObject()->getType()); @@ -239,7 +233,6 @@ class ConditionalFormattingDataBarXlsxTest extends TestCase //ext $rule1ext = $dataBar->getConditionalFormattingRuleExt(); - self::assertNotNull($rule1ext); self::assertEquals('{453C04BA-7ABD-8548-8A17-D9CFD2BDABE9}', $rule1ext->getId()); self::assertEquals('dataBar', $rule1ext->getCfRule()); self::assertEquals('C3:C23', $rule1ext->getSqref()); @@ -289,7 +282,6 @@ class ConditionalFormattingDataBarXlsxTest extends TestCase self::assertNotEmpty($dataBar); self::assertEquals(Conditional::CONDITION_DATABAR, $conditionalRule->getConditionType()); - self::assertNotNull($dataBar); self::assertTrue($dataBar->getShowValue()); self::assertNotNull($dataBar->getMinimumConditionalFormatValueObject()); self::assertNotNull($dataBar->getMaximumConditionalFormatValueObject()); @@ -302,7 +294,6 @@ class ConditionalFormattingDataBarXlsxTest extends TestCase //ext $rule1ext = $dataBar->getConditionalFormattingRuleExt(); - self::assertNotNull($rule1ext); self::assertEquals('{6C1E066A-E240-3D4A-98F8-8CC218B0DFD2}', $rule1ext->getId()); self::assertEquals('dataBar', $rule1ext->getCfRule()); self::assertEquals('D3:D23', $rule1ext->getSqref()); diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/PropertiesTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/PropertiesTest.php index 803477a8f..2624a8646 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xlsx/PropertiesTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/PropertiesTest.php @@ -38,7 +38,6 @@ class PropertiesTest extends AbstractFunctional // Custom Properties $customProperties = $properties->getCustomProperties(); - self::assertIsArray($customProperties); $customProperties = array_flip($customProperties); self::assertArrayHasKey('Publisher', $customProperties); @@ -81,7 +80,6 @@ class PropertiesTest extends AbstractFunctional // Custom Properties $customProperties = $properties->getCustomProperties(); - self::assertIsArray($customProperties); $customProperties = array_flip($customProperties); self::assertArrayHasKey('Publisher', $customProperties); diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/VmlTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/VmlTest.php index 11783a9c6..971ef0ad9 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xlsx/VmlTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/VmlTest.php @@ -118,7 +118,6 @@ class VmlTest extends TestCase $reader = new XlsxReader(); $reader->setLoadSheetsOnly('FormsComments'); $spreadsheet = $reader->load($infile); - self::assertTrue(true); $sheet = $spreadsheet->getActiveSheet(); self::assertSame('row1', $sheet->getCell('H1')->getValue()); self::assertStringContainsString('Hello', $sheet->getComment('F1')->getText()->getPlainText()); diff --git a/tests/PhpSpreadsheetTests/Reader/Xlsx/XlsxTest.php b/tests/PhpSpreadsheetTests/Reader/Xlsx/XlsxTest.php index 3b5bbb193..7ce2ca7c1 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xlsx/XlsxTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xlsx/XlsxTest.php @@ -123,7 +123,6 @@ class XlsxTest extends TestCase $worksheet = $spreadsheet->getActiveSheet(); $autofilter = $worksheet->getAutoFilter(); - self::assertInstanceOf(AutoFilter::class, $autofilter); self::assertEquals('A1:D57', $autofilter->getRange()); self::assertEquals( AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER, @@ -167,7 +166,7 @@ class XlsxTest extends TestCase self::assertEquals(Conditional::CONDITION_CELLIS, $conditionalRule->getConditionType()); self::assertEquals(Conditional::OPERATOR_BETWEEN, $conditionalRule->getOperatorType()); self::assertEquals(['200', '400'], $conditionalRule->getConditions()); - self::assertInstanceOf(Style::class, $conditionalRule->getStyle()); + self::assertSame('#,##0.00_-"€"', $conditionalRule->getStyle()->exportArray()['numberFormat']['formatCode']); $spreadsheet->disconnectWorksheets(); } diff --git a/tests/PhpSpreadsheetTests/ReferenceHelper2Test.php b/tests/PhpSpreadsheetTests/ReferenceHelper2Test.php index c3f8484f0..754b26006 100644 --- a/tests/PhpSpreadsheetTests/ReferenceHelper2Test.php +++ b/tests/PhpSpreadsheetTests/ReferenceHelper2Test.php @@ -16,7 +16,8 @@ class ReferenceHelper2Test extends TestCase $this->expectException(SpreadsheetException::class); $this->expectExceptionMessage('Cloning a Singleton'); $referenceHelper = ReferenceHelper::getInstance(); - clone $referenceHelper; + $x = clone $referenceHelper; + $x->updateFormulaReferences(); } public function testRenamedWorksheetInFormula(): void diff --git a/tests/PhpSpreadsheetTests/RichTextTest.php b/tests/PhpSpreadsheetTests/RichTextTest.php index 513dcf7a9..db413585c 100644 --- a/tests/PhpSpreadsheetTests/RichTextTest.php +++ b/tests/PhpSpreadsheetTests/RichTextTest.php @@ -54,7 +54,6 @@ class RichTextTest extends TestCase { $richText = new RichText(); $textRun = $richText->createTextRun('hello'); - self::assertNotNull($textRun->getFontOrThrow()); $textRun->setFont(null); try { diff --git a/tests/PhpSpreadsheetTests/SettingsTest.php b/tests/PhpSpreadsheetTests/SettingsTest.php index 5a4d1518c..576198ff7 100644 --- a/tests/PhpSpreadsheetTests/SettingsTest.php +++ b/tests/PhpSpreadsheetTests/SettingsTest.php @@ -33,7 +33,6 @@ class SettingsTest extends TestCase public function testCache(): void { $cache1 = Settings::getCache(); - self::assertNotNull($cache1); Settings::setCache(null); $cache2 = Settings::getCache(); self::assertEquals($cache1, $cache2); diff --git a/tests/PhpSpreadsheetTests/Shared/DateTest.php b/tests/PhpSpreadsheetTests/Shared/DateTest.php index e3dbedb6b..3559b6a33 100644 --- a/tests/PhpSpreadsheetTests/Shared/DateTest.php +++ b/tests/PhpSpreadsheetTests/Shared/DateTest.php @@ -159,7 +159,7 @@ class DateTest extends TestCase #[\PHPUnit\Framework\Attributes\DataProvider('providerDateTimeExcelToTimestamp1900Timezone')] public function testDateTimeExcelToTimestamp1900Timezone(float|int $expectedResult, float|int $excelDateTimeValue, string $timezone): void { - if (is_numeric($expectedResult) && ($expectedResult > PHP_INT_MAX || $expectedResult < PHP_INT_MIN)) { + if ($expectedResult > PHP_INT_MAX || $expectedResult < PHP_INT_MIN) { self::markTestSkipped('Test invalid on 32-bit system.'); } Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); @@ -201,34 +201,30 @@ class DateTest extends TestCase 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)); + self::assertTrue(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)); + self::assertTrue(Date::isDateTime($cella2)); $cella3 = $sheet->getCell('A3'); - self::assertNotNull($cella3); $cella3->setValue('=A1+4'); $sheet->getStyle('A3') ->getNumberFormat() ->setFormatCode('0.00E+00'); - self::assertFalse(null !== $cella3 && Date::isDateTime($cella3)); + self::assertFalse(Date::isDateTime($cella3)); $cella4 = $sheet->getCell('A4'); - self::assertNotNull($cella4); $cella4->setValue('= 44 7510557347'); $sheet->getStyle('A4') diff --git a/tests/PhpSpreadsheetTests/Shared/ExactFontTest.php b/tests/PhpSpreadsheetTests/Shared/ExactFontTest.php index fcae3303b..a6652fbb6 100644 --- a/tests/PhpSpreadsheetTests/Shared/ExactFontTest.php +++ b/tests/PhpSpreadsheetTests/Shared/ExactFontTest.php @@ -156,31 +156,28 @@ class ExactFontTest extends TestCase $font->setSize(20); $exactWidth = Font::calculateColumnWidth($font, 'Column2'); $expectedWidth = 16.853; - if ($exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth) { - self::assertTrue(true); - } else { - self::fail("$exactWidth is not within 5% of expected $expectedWidth"); - } + self::assertTrue( + $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, + "$exactWidth is not within 5% of expected $expectedWidth" + ); $font = new StyleFont(); $font->setName($fontName); $exactWidth = Font::calculateColumnWidth($font, 'Col3'); $expectedWidth = 4.5703; - if ($exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth) { - self::assertTrue(true); - } else { - self::fail("$exactWidth is not within 5% of expected $expectedWidth"); - } + self::assertTrue( + $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, + "$exactWidth is not within 5% of expected $expectedWidth" + ); $font = new StyleFont(); $font->setName($fontName); $exactWidth = Font::calculateColumnWidth($font, 'Big Column in 4 position'); $expectedWidth = 26.2793; - if ($exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth) { - self::assertTrue(true); - } else { - self::fail("$exactWidth is not within 5% of expected $expectedWidth"); - } + self::assertTrue( + $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, + "$exactWidth is not within 5% of expected $expectedWidth" + ); } public function testIssue3626Pad(): void @@ -199,30 +196,27 @@ class ExactFontTest extends TestCase $font->setSize(20); $exactWidth = Font::calculateColumnWidth($font, 'Column2'); $expectedWidth = 18.8525; - if ($exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth) { - self::assertTrue(true); - } else { - self::fail("$exactWidth is not within 5% of expected $expectedWidth"); - } + self::assertTrue( + $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, + "$exactWidth is not within 5% of expected $expectedWidth" + ); $font = new StyleFont(); $font->setName($fontName); $exactWidth = Font::calculateColumnWidth($font, 'Col3'); $expectedWidth = 5.8557; - if ($exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth) { - self::assertTrue(true); - } else { - self::fail("$exactWidth is not within 5% of expected $expectedWidth"); - } + self::assertTrue( + $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, + "$exactWidth is not within 5% of expected $expectedWidth" + ); $font = new StyleFont(); $font->setName($fontName); $exactWidth = Font::calculateColumnWidth($font, 'Big Column in 4 position'); $expectedWidth = 27.5647; - if ($exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth) { - self::assertTrue(true); - } else { - self::fail("$exactWidth is not within 5% of expected $expectedWidth"); - } + self::assertTrue( + $exactWidth > 0.95 * $expectedWidth && $exactWidth < 1.05 * $expectedWidth, + "$exactWidth is not within 5% of expected $expectedWidth" + ); } } diff --git a/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/BlankWizardTest.php b/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/BlankWizardTest.php index d9a64fd5c..3d36c896b 100644 --- a/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/BlankWizardTest.php +++ b/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/BlankWizardTest.php @@ -27,7 +27,6 @@ class BlankWizardTest extends TestCase public function testBlankWizard(): void { $ruleType = Wizard::BLANKS; - /** @var Wizard\Blanks $wizard */ $wizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\Blanks::class, $wizard); $wizard->setStyle($this->style); @@ -45,7 +44,6 @@ class BlankWizardTest extends TestCase public function testNonBlankWizard(): void { $ruleType = Wizard::NOT_BLANKS; - /** @var Wizard\Blanks $wizard */ $wizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\Blanks::class, $wizard); $wizard->setStyle($this->style); diff --git a/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/DuplicatesWizardTest.php b/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/DuplicatesWizardTest.php index 8c5082a30..26a534e08 100644 --- a/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/DuplicatesWizardTest.php +++ b/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/DuplicatesWizardTest.php @@ -27,7 +27,6 @@ class DuplicatesWizardTest extends TestCase public function testDuplicateWizard(): void { $ruleType = Wizard::DUPLICATES; - /** @var Wizard\Duplicates $wizard */ $wizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\Duplicates::class, $wizard); $wizard->setStyle($this->style); @@ -43,7 +42,6 @@ class DuplicatesWizardTest extends TestCase public function testUniqueWizard(): void { $ruleType = Wizard::UNIQUE; - /** @var Wizard\Duplicates $wizard */ $wizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\Duplicates::class, $wizard); $wizard->setStyle($this->style); diff --git a/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/ErrorWizardTest.php b/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/ErrorWizardTest.php index 8026135aa..967a94115 100644 --- a/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/ErrorWizardTest.php +++ b/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/ErrorWizardTest.php @@ -27,7 +27,6 @@ class ErrorWizardTest extends TestCase public function testErrorWizard(): void { $ruleType = Wizard::ERRORS; - /** @var Wizard\Errors $wizard */ $wizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\Errors::class, $wizard); $wizard->setStyle($this->style); @@ -45,7 +44,6 @@ class ErrorWizardTest extends TestCase public function testNonErrorWizard(): void { $ruleType = Wizard::NOT_ERRORS; - /** @var Wizard\Errors $wizard */ $wizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\Errors::class, $wizard); $wizard->setStyle($this->style); diff --git a/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/TextValueWizardTest.php b/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/TextValueWizardTest.php index cd89dd347..5ab24307c 100644 --- a/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/TextValueWizardTest.php +++ b/tests/PhpSpreadsheetTests/Style/ConditionalFormatting/Wizard/TextValueWizardTest.php @@ -27,7 +27,6 @@ class TextValueWizardTest extends TestCase public function testTextContainsWizardWithText(): void { $ruleType = Wizard::TEXT_VALUE; - /** @var Wizard\TextValue $textWizard */ $textWizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\TextValue::class, $textWizard); @@ -49,7 +48,6 @@ class TextValueWizardTest extends TestCase public function testTextContainsWizardWithCellReference(): void { $ruleType = Wizard::TEXT_VALUE; - /** @var Wizard\TextValue $textWizard */ $textWizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\TextValue::class, $textWizard); @@ -71,7 +69,6 @@ class TextValueWizardTest extends TestCase public function testTextNotContainsWizardWithText(): void { $ruleType = Wizard::TEXT_VALUE; - /** @var Wizard\TextValue $textWizard */ $textWizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\TextValue::class, $textWizard); @@ -93,7 +90,6 @@ class TextValueWizardTest extends TestCase public function testTextBeginsWithWizardWithText(): void { $ruleType = Wizard::TEXT_VALUE; - /** @var Wizard\TextValue $textWizard */ $textWizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\TextValue::class, $textWizard); @@ -115,7 +111,6 @@ class TextValueWizardTest extends TestCase public function testTextEndsWithWizardWithText(): void { $ruleType = Wizard::TEXT_VALUE; - /** @var Wizard\TextValue $textWizard */ $textWizard = $this->wizardFactory->newRule($ruleType); self::assertInstanceOf(Wizard\TextValue::class, $textWizard); diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTest.php index 7981687bd..1d82822d9 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/AutoFilterTest.php @@ -43,7 +43,7 @@ class AutoFilterTest extends SetupTeardown $sheet2 = $spreadsheet->createSheet(); // Setters return the instance to implement the fluent interface $result = $autoFilter->setParent($sheet2); - self::assertInstanceOf(AutoFilter::class, $result); + self::assertSame(self::INITIAL_RANGE, $result->getRange()); } public function testGetRange(): void @@ -73,7 +73,6 @@ class AutoFilterTest extends SetupTeardown foreach ($ranges as $actualRange => $fullRange) { // Setters return the instance to implement the fluent interface $result = $autoFilter->setRange($fullRange); - self::assertInstanceOf(AutoFilter::class, $result); // Result should be the new autofilter range $result = $autoFilter->getRange(); @@ -90,7 +89,6 @@ class AutoFilterTest extends SetupTeardown // Setters return the instance to implement the fluent interface $result = $autoFilter->setRange(''); - self::assertInstanceOf(AutoFilter::class, $result); // Result should be a clear range $result = $autoFilter->getRange(); @@ -125,8 +123,7 @@ class AutoFilterTest extends SetupTeardown $sheet = $this->getSheet(); $autoFilter = $sheet->getAutoFilter(); $result = $autoFilter->getColumns(); - self::assertIsArray($result); - self::assertCount(0, $result); + self::assertSame([], $result); } public function testGetColumnOffset(): void @@ -227,15 +224,12 @@ class AutoFilterTest extends SetupTeardown // Setters return the instance to implement the fluent interface $result = $autoFilter->setColumn($expectedResult); - self::assertInstanceOf(AutoFilter::class, $result); $result = $autoFilter->getColumns(); // Result should be an array of \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column // objects for each column we set indexed by the column ID - self::assertIsArray($result); self::assertCount(1, $result); self::assertArrayHasKey($expectedResult, $result); - self::assertInstanceOf(Column::class, $result[$expectedResult]); } public function testSetInvalidColumnWithString(): void @@ -260,15 +254,12 @@ class AutoFilterTest extends SetupTeardown // Setters return the instance to implement the fluent interface $result = $autoFilter->setColumn($columnObject); - self::assertInstanceOf(AutoFilter::class, $result); $result = $autoFilter->getColumns(); // Result should be an array of \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column // objects for each column we set indexed by the column ID - self::assertIsArray($result); self::assertCount(1, $result); self::assertArrayHasKey($expectedResult, $result); - self::assertInstanceOf(Column::class, $result[$expectedResult]); } public function testSetInvalidColumnWithObject(): void @@ -297,11 +288,9 @@ class AutoFilterTest extends SetupTeardown $result = $autoFilter->getColumns(); // Result should be an array of \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column // objects for each column we set indexed by the column ID - self::assertIsArray($result); self::assertCount(count($columnIndexes), $result); foreach ($columnIndexes as $columnIndex) { self::assertArrayHasKey($columnIndex, $result); - self::assertInstanceOf(Column::class, $result[$columnIndex]); } $autoFilter->setRange(''); @@ -325,7 +314,7 @@ class AutoFilterTest extends SetupTeardown // get a \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column object returned foreach ($columnIndexes as $columnIndex) { $result = $autoFilter->getColumn($columnIndex); - self::assertInstanceOf(Column::class, $result); + self::assertSame($columnIndex, $result->getColumnIndex()); } } @@ -345,7 +334,6 @@ class AutoFilterTest extends SetupTeardown // get a \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column object returned foreach ($columnIndexes as $columnIndex => $columnID) { $result = $autoFilter->getColumnByOffset($columnIndex); - self::assertInstanceOf(Column::class, $result); self::assertEquals($result->getColumnIndex(), $columnID); } } @@ -358,7 +346,7 @@ class AutoFilterTest extends SetupTeardown // If we request a specific column by its column ID, we should // get a \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column object returned $result = $autoFilter->getColumn('K'); - self::assertInstanceOf(Column::class, $result); + self::assertSame('K', $result->getColumnIndex()); } public function testGetColumnWithoutRangeSet(): void @@ -387,7 +375,6 @@ class AutoFilterTest extends SetupTeardown // Setters return the instance to implement the fluent interface $result = $autoFilter->setRange(''); - self::assertInstanceOf(AutoFilter::class, $result); // Range should be cleared $result = $autoFilter->getRange(); @@ -395,8 +382,7 @@ class AutoFilterTest extends SetupTeardown // Column array should be cleared $result = $autoFilter->getColumns(); - self::assertIsArray($result); - self::assertCount(0, $result); + self::assertSame([], $result); } public function testSetRangeWithExistingColumns(): void @@ -419,7 +405,6 @@ class AutoFilterTest extends SetupTeardown // Setters return the instance to implement the fluent interface $result = $autoFilter->setRange($expectedResult); - self::assertInstanceOf(AutoFilter::class, $result); // Range should be correctly set $result = $autoFilter->getRange(); @@ -428,7 +413,6 @@ class AutoFilterTest extends SetupTeardown // Only columns that existed in the original range and that // still fall within the new range should be retained $result = $autoFilter->getColumns(); - self::assertIsArray($result); self::assertCount(count($columnIndexes1), $result); } @@ -444,25 +428,17 @@ class AutoFilterTest extends SetupTeardown } $result = clone $autoFilter; - self::assertInstanceOf(AutoFilter::class, $result); self::assertSame($autoFilter->getRange(), $result->getRange()); self::assertNull($result->getParent()); - self::assertNotNull($autoFilter->getParent()); self::assertInstanceOf(Worksheet::class, $autoFilter->getParent()); $autoColumns = $autoFilter->getColumns(); $resultColumns = $result->getColumns(); - self::assertIsArray($autoColumns); - self::assertIsArray($resultColumns); self::assertCount(2, $autoColumns); self::assertCount(2, $resultColumns); self::assertArrayHasKey('L', $autoColumns); self::assertArrayHasKey('L', $resultColumns); self::assertArrayHasKey('M', $autoColumns); self::assertArrayHasKey('M', $resultColumns); - self::assertInstanceOf(Column::class, $autoColumns['L']); - self::assertInstanceOf(Column::class, $resultColumns['L']); - self::assertInstanceOf(Column::class, $autoColumns['M']); - self::assertInstanceOf(Column::class, $resultColumns['M']); } public function testNoWorksheet(): void diff --git a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php index 4e7e48348..e4f103a22 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php @@ -64,7 +64,6 @@ class ColumnTest extends SetupTeardown $expectedResult = 'G'; $result = $columnFilter->setColumnIndex($expectedResult); - self::assertInstanceOf(Column::class, $result); $result = $result->getColumnIndex(); self::assertEquals($expectedResult, $result); @@ -76,7 +75,7 @@ class ColumnTest extends SetupTeardown $columnFilter = $sheet->getAutoFilter()->getColumn('H'); // Setters return the instance to implement the fluent interface $result = $columnFilter->setParent(null); - self::assertInstanceOf(Column::class, $result); + self::assertSame('filters', $columnFilter->getFilterType()); } public function testVariousSets(): void @@ -91,13 +90,11 @@ class ColumnTest extends SetupTeardown ); $result = $columnFilter->setFilterType(Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER); - self::assertInstanceOf(Column::class, $result); $result = $columnFilter->getFilterType(); self::assertEquals(Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER, $result); $result = $columnFilter->setJoin(Column::AUTOFILTER_COLUMN_JOIN_AND); - self::assertInstanceOf(Column::class, $result); $result = $columnFilter->getJoin(); self::assertEquals(Column::AUTOFILTER_COLUMN_JOIN_AND, $result); @@ -155,7 +152,6 @@ class ColumnTest extends SetupTeardown ]; $result = $columnFilter->setAttributes($attributeSet); - self::assertInstanceOf(Column::class, $result); $result = $columnFilter->getAttributes(); self::assertSame($attributeSet, $result); @@ -180,7 +176,6 @@ class ColumnTest extends SetupTeardown foreach ($attributeSet as $attributeName => $attributeValue) { // Setters return the instance to implement the fluent interface $result = $columnFilter->setAttribute($attributeName, $attributeValue); - self::assertInstanceOf(Column::class, $result); } self::assertSame($attributeSet, $columnFilter->getAttributes()); } @@ -255,7 +250,6 @@ class ColumnTest extends SetupTeardown $rule0 = $columnFilter->getRule(0); self::assertSame($originalRules[0], $rule0); $rule1 = $columnFilter->getRule(1); - self::assertInstanceOf(Rule::class, $rule1); self::assertNotEquals($originalRules[0], $rule1); self::assertCount(2, $columnFilter->getRules()); self::assertSame(Column::AUTOFILTER_COLUMN_JOIN_OR, $columnFilter->getJoin()); diff --git a/tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowTest.php b/tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowTest.php index 642a7eac0..e32de6684 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowTest.php @@ -5,9 +5,7 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Cell\DataType; -use PhpOffice\PhpSpreadsheet\Comment; use PhpOffice\PhpSpreadsheet\Spreadsheet; -use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PHPUnit\Framework\TestCase; @@ -166,7 +164,6 @@ class ByColumnAndRowTest extends TestCase $sheet->setAutoFilter([2, 2, 3, 3]); $autoFilter = $sheet->getAutoFilter(); - self::assertInstanceOf(AutoFilter::class, $autoFilter); self::assertSame('B2:C3', $autoFilter->getRange()); $spreadsheet->disconnectWorksheets(); } @@ -196,7 +193,6 @@ class ByColumnAndRowTest extends TestCase ->getText()->createTextRun('My Test Comment'); $comment = $sheet->getComment([2, 2]); - self::assertInstanceOf(Comment::class, $comment); self::assertSame('My Test Comment', $comment->getText()->getPlainText()); $spreadsheet->disconnectWorksheets(); } diff --git a/tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowUndeprecatedTest.php b/tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowUndeprecatedTest.php index 0a761ada0..cc18bfaea 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowUndeprecatedTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ByColumnAndRowUndeprecatedTest.php @@ -5,10 +5,8 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Cell\DataType; -use PhpOffice\PhpSpreadsheet\Comment; use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException; use PhpOffice\PhpSpreadsheet\Spreadsheet; -use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PHPUnit\Framework\TestCase; @@ -174,7 +172,6 @@ class ByColumnAndRowUndeprecatedTest extends TestCase $sheet->setAutoFilter([2, 2, 3, 3]); $autoFilter = $sheet->getAutoFilter(); - self::assertInstanceOf(AutoFilter::class, $autoFilter); self::assertSame('B2:C3', $autoFilter->getRange()); } @@ -202,7 +199,6 @@ class ByColumnAndRowUndeprecatedTest extends TestCase ->getText()->createTextRun('My Test Comment'); $comment = $sheet->getComment([2, 2]); - self::assertInstanceOf(Comment::class, $comment); self::assertSame('My Test Comment', $comment->getText()->getPlainText()); } diff --git a/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIterator2Test.php b/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIterator2Test.php index 9c889c69b..568e214f2 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIterator2Test.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIterator2Test.php @@ -4,14 +4,22 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Worksheet; +use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\CellIterator; use PhpOffice\PhpSpreadsheet\Worksheet\ColumnCellIterator; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class ColumnCellIterator2Test extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('providerExistingCell')] + // Phpstan does not think RowCellIterator can return null + private static function isCellNull(?Cell $item): bool + { + return $item === null; + } + + #[DataProvider('providerExistingCell')] public function testEndRange(?bool $existing, string $expectedResultFirst, string $expectedResultLast): void { $spreadsheet = new Spreadsheet(); @@ -26,7 +34,7 @@ class ColumnCellIterator2Test extends TestCase $lastCoordinate = ''; $firstCoordinate = ''; foreach ($iterator as $cell) { - if ($cell !== null) { + if (!self::isCellNull($cell)) { $lastCoordinate = $cell->getCoordinate(); if (!$firstCoordinate) { $firstCoordinate = $lastCoordinate; @@ -46,7 +54,7 @@ class ColumnCellIterator2Test extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerEmptyColumn')] + #[DataProvider('providerEmptyColumn')] public function testEmptyColumn(?bool $existing, int $expectedResult): void { $spreadsheet = new Spreadsheet(); @@ -74,7 +82,7 @@ class ColumnCellIterator2Test extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerNullOrCreate')] + #[DataProvider('providerNullOrCreate')] public function testNullOrCreateOption(?bool $existingBehaviour, int $expectedCreatedResult): void { $spreadsheet = new Spreadsheet(); @@ -87,7 +95,7 @@ class ColumnCellIterator2Test extends TestCase self::assertSame($expectedCreatedResult > 0, $notExistsBehaviour); } - #[\PHPUnit\Framework\Attributes\DataProvider('providerNullOrCreate')] + #[DataProvider('providerNullOrCreate')] public function testNullOrCreate(?bool $existing, int $expectedCreatedResult, int $expectedNullResult): void { $spreadsheet = new Spreadsheet(); @@ -101,9 +109,8 @@ class ColumnCellIterator2Test extends TestCase } $numCreatedCells = $numEmptyCells = 0; foreach ($iterator as $cell) { - $numCreatedCells += (int) ($cell !== null && $cell->getValue() === null); - // @phpstan-ignore-next-line - $numEmptyCells += (int) ($cell === null); + $numCreatedCells += (int) (!self::isCellNull($cell) && $cell->getValue() === null); + $numEmptyCells += (int) (self::isCellNull($cell)); } self::assertSame($expectedCreatedResult, $numCreatedCells); self::assertSame($expectedNullResult, $numEmptyCells); diff --git a/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php index b57accb1d..b217acb0a 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php @@ -23,6 +23,12 @@ class ColumnCellIteratorTest extends TestCase [160, null, 360, null, 560], ]; + // Phpstan does not think RowCellIterator can return null + private static function isCellNull(?Cell $item): bool + { + return $item === null; + } + private static function getPopulatedSheet(Spreadsheet $spreadsheet): Worksheet { $sheet = $spreadsheet->getActiveSheet(); @@ -41,10 +47,9 @@ class ColumnCellIteratorTest extends TestCase $values = []; foreach ($iterator as $key => $ColumnCell) { - self::assertNotNull($ColumnCell); + self::assertFalse(self::isCellNull($ColumnCell)); $values[] = $ColumnCell->getValue(); self::assertEquals($ColumnCellIndexResult++, $key); - self::assertInstanceOf(Cell::class, $ColumnCell); } $transposed = array_map(null, ...self::CELL_VALUES); self::assertSame($transposed[0], $values); @@ -61,10 +66,9 @@ class ColumnCellIteratorTest extends TestCase $values = []; foreach ($iterator as $key => $ColumnCell) { - self::assertNotNull($ColumnCell); + self::assertFalse(self::isCellNull($ColumnCell)); $values[] = $ColumnCell->getValue(); self::assertEquals($ColumnCellIndexResult++, $key); - self::assertInstanceOf(Cell::class, $ColumnCell); } self::assertSame([120, 130, 140], $values); $spreadsheet->disconnectWorksheets(); diff --git a/tests/PhpSpreadsheetTests/Worksheet/ColumnDimensionTest.php b/tests/PhpSpreadsheetTests/Worksheet/ColumnDimensionTest.php index ee5cc92ed..0a0ac2262 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ColumnDimensionTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ColumnDimensionTest.php @@ -14,7 +14,6 @@ class ColumnDimensionTest extends TestCase { $expected = 'A'; $columnDimension = new ColumnDimension(); - self::assertInstanceOf(ColumnDimension::class, $columnDimension); $result = $columnDimension->getColumnIndex(); self::assertEquals($expected, $result); } diff --git a/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php index e6a2cee79..540a291f5 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php @@ -6,7 +6,6 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Exception as Except; use PhpOffice\PhpSpreadsheet\Spreadsheet; -use PhpOffice\PhpSpreadsheet\Worksheet\Column; use PhpOffice\PhpSpreadsheet\Worksheet\ColumnIterator; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PHPUnit\Framework\TestCase; @@ -40,7 +39,6 @@ class ColumnIteratorTest extends TestCase foreach ($iterator as $key => $column) { ++$counter; self::assertEquals($columnIndexResult++, $key); - self::assertInstanceOf(Column::class, $column); } self::assertCount($counter, self::CELL_VALUES[0]); $spreadsheet->disconnectWorksheets(); @@ -58,7 +56,6 @@ class ColumnIteratorTest extends TestCase foreach ($iterator as $key => $column) { ++$counter; self::assertEquals($columnIndexResult++, $key); - self::assertInstanceOf(Column::class, $column); } self::assertSame(3, $counter); $spreadsheet->disconnectWorksheets(); diff --git a/tests/PhpSpreadsheetTests/Worksheet/ColumnTest.php b/tests/PhpSpreadsheetTests/Worksheet/ColumnTest.php index b2c0b7515..fd311c2b9 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ColumnTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ColumnTest.php @@ -6,7 +6,6 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\Column; -use PhpOffice\PhpSpreadsheet\Worksheet\ColumnCellIterator; use PHPUnit\Framework\TestCase; class ColumnTest extends TestCase @@ -16,7 +15,6 @@ class ColumnTest extends TestCase $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $column = new Column($sheet); - self::assertInstanceOf(Column::class, $column); $columnIndex = $column->getColumnIndex(); self::assertEquals('A', $columnIndex); $spreadsheet->disconnectWorksheets(); @@ -27,7 +25,6 @@ class ColumnTest extends TestCase $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $column = new Column($sheet, 'E'); - self::assertInstanceOf(Column::class, $column); $columnIndex = $column->getColumnIndex(); self::assertEquals('E', $columnIndex); $spreadsheet->disconnectWorksheets(); @@ -39,7 +36,7 @@ class ColumnTest extends TestCase $sheet = $spreadsheet->getActiveSheet(); $column = new Column($sheet); $cellIterator = $column->getCellIterator(); - self::assertInstanceOf(ColumnCellIterator::class, $cellIterator); + self::assertSame(1, $cellIterator->key()); $spreadsheet->disconnectWorksheets(); } @@ -49,7 +46,7 @@ class ColumnTest extends TestCase $sheet = $spreadsheet->getActiveSheet(); $column = new Column($sheet); $cellIterator = $column->getRowIterator(); - self::assertInstanceOf(ColumnCellIterator::class, $cellIterator); + self::assertSame(1, $cellIterator->key()); $spreadsheet->disconnectWorksheets(); } } diff --git a/tests/PhpSpreadsheetTests/Worksheet/IteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/IteratorTest.php index cf3eca54e..43d548116 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/IteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/IteratorTest.php @@ -6,7 +6,6 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\Iterator; -use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PHPUnit\Framework\TestCase; class IteratorTest extends TestCase @@ -23,7 +22,6 @@ class IteratorTest extends TestCase foreach ($iterator as $key => $column) { self::assertEquals($columnIndexResult++, $key); - self::assertInstanceOf(Worksheet::class, $column); } self::assertSame(3, $columnIndexResult); } diff --git a/tests/PhpSpreadsheetTests/Worksheet/MemoryDrawingTest.php b/tests/PhpSpreadsheetTests/Worksheet/MemoryDrawingTest.php index 307496143..a1fc0483f 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/MemoryDrawingTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/MemoryDrawingTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Worksheet; -use GdImage; use PhpOffice\PhpSpreadsheet\Exception; use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing; use PHPUnit\Framework\TestCase; @@ -31,7 +30,6 @@ class MemoryDrawingTest extends TestCase $drawing->setMimeType(MemoryDrawing::MIMETYPE_PNG); self::assertIsObject($drawing->getImageResource()); - self::assertInstanceOf(GdImage::class, $drawing->getImageResource()); self::assertSame(MemoryDrawing::MIMETYPE_DEFAULT, $drawing->getMimeType()); self::assertSame(MemoryDrawing::RENDERING_DEFAULT, $drawing->getRenderingFunction()); @@ -48,7 +46,6 @@ class MemoryDrawingTest extends TestCase $drawing = MemoryDrawing::fromString($imageString); self::assertIsObject($drawing->getImageResource()); - self::assertInstanceOf(GdImage::class, $drawing->getImageResource()); self::assertSame(MemoryDrawing::MIMETYPE_JPEG, $drawing->getMimeType()); self::assertSame(MemoryDrawing::RENDERING_JPEG, $drawing->getRenderingFunction()); @@ -75,7 +72,6 @@ class MemoryDrawingTest extends TestCase fclose($imageStream); self::assertIsObject($drawing->getImageResource()); - self::assertInstanceOf(GdImage::class, $drawing->getImageResource()); self::assertSame(MemoryDrawing::MIMETYPE_JPEG, $drawing->getMimeType()); self::assertSame(MemoryDrawing::RENDERING_JPEG, $drawing->getRenderingFunction()); diff --git a/tests/PhpSpreadsheetTests/Worksheet/RowCellIterator2Test.php b/tests/PhpSpreadsheetTests/Worksheet/RowCellIterator2Test.php index 64f7da264..164c78a3e 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/RowCellIterator2Test.php +++ b/tests/PhpSpreadsheetTests/Worksheet/RowCellIterator2Test.php @@ -4,14 +4,22 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Worksheet; +use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\CellIterator; use PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class RowCellIterator2Test extends TestCase { - #[\PHPUnit\Framework\Attributes\DataProvider('providerExistingCell')] + // Phpstan does not think RowCellIterator can return null + private static function isCellNull(?Cell $item): bool + { + return $item === null; + } + + #[DataProvider('providerExistingCell')] public function testEndRangeTrue(?bool $existing, string $expectedResultFirst, string $expectedResultLast): void { $spreadsheet = new Spreadsheet(); @@ -26,7 +34,7 @@ class RowCellIterator2Test extends TestCase $lastCoordinate = ''; $firstCoordinate = ''; foreach ($iterator as $cell) { - if ($cell !== null) { + if (!self::isCellNull($cell)) { $lastCoordinate = $cell->getCoordinate(); if (!$firstCoordinate) { $firstCoordinate = $lastCoordinate; @@ -46,7 +54,7 @@ class RowCellIterator2Test extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerEmptyRow')] + #[DataProvider('providerEmptyRow')] public function testEmptyRow(?bool $existing, int $expectedResult): void { $spreadsheet = new Spreadsheet(); @@ -74,7 +82,7 @@ class RowCellIterator2Test extends TestCase ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerNullOrCreate')] + #[DataProvider('providerNullOrCreate')] public function testNullOrCreateOption(?bool $existingBehaviour, int $expectedCreatedResult): void { $spreadsheet = new Spreadsheet(); @@ -87,7 +95,7 @@ class RowCellIterator2Test extends TestCase self::assertSame($expectedCreatedResult > 0, $notExistsBehaviour); } - #[\PHPUnit\Framework\Attributes\DataProvider('providerNullOrCreate')] + #[DataProvider('providerNullOrCreate')] public function testNullOrCreate(?bool $existing, int $expectedCreatedResult, int $expectedNullResult): void { $spreadsheet = new Spreadsheet(); @@ -101,9 +109,8 @@ class RowCellIterator2Test extends TestCase } $numCreatedCells = $numEmptyCells = 0; foreach ($iterator as $cell) { - $numCreatedCells += (int) ($cell !== null && $cell->getValue() === null); - // @phpstan-ignore-next-line - $numEmptyCells += (int) ($cell === null); + $numCreatedCells += (int) (!self::isCellNull($cell) && $cell->getValue() === null); + $numEmptyCells += (int) self::isCellNull($cell); } self::assertSame($expectedCreatedResult, $numCreatedCells); self::assertSame($expectedNullResult, $numEmptyCells); diff --git a/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php index 08736e3c8..ce85e94ae 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Worksheet; -use PhpOffice\PhpSpreadsheet\Cell\Cell; use PhpOffice\PhpSpreadsheet\Exception as Except; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator; @@ -41,10 +40,8 @@ class RowCellIteratorTest extends TestCase $values = []; foreach ($iterator as $key => $RowCell) { - self::assertNotNull($RowCell); $values[] = $RowCell->getValue(); self::assertEquals($RowCellIndexResult++, $key); - self::assertInstanceOf(Cell::class, $RowCell); } self::assertSame(self::CELL_VALUES[0], $values); $spreadsheet->disconnectWorksheets(); @@ -60,10 +57,8 @@ class RowCellIteratorTest extends TestCase $values = []; foreach ($iterator as $key => $RowCell) { - self::assertNotNull($RowCell); $values[] = $RowCell->getValue(); self::assertEquals($RowCellIndexResult++, $key); - self::assertInstanceOf(Cell::class, $RowCell); } self::assertSame([220, 230, 240], $values); $spreadsheet->disconnectWorksheets(); diff --git a/tests/PhpSpreadsheetTests/Worksheet/RowDimensionTest.php b/tests/PhpSpreadsheetTests/Worksheet/RowDimensionTest.php index 1782ba52f..2b2acd7e5 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/RowDimensionTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/RowDimensionTest.php @@ -14,7 +14,6 @@ class RowDimensionTest extends TestCase { $expected = 0; $rowDimension = new RowDimension(); - self::assertInstanceOf(RowDimension::class, $rowDimension); $result = $rowDimension->getRowIndex(); self::assertEquals($expected, $result); } diff --git a/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php index 9c3e50c6d..f90b2d669 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php @@ -6,7 +6,6 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Exception as Except; use PhpOffice\PhpSpreadsheet\Spreadsheet; -use PhpOffice\PhpSpreadsheet\Worksheet\Row; use PhpOffice\PhpSpreadsheet\Worksheet\RowIterator; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; use PHPUnit\Framework\TestCase; @@ -43,7 +42,6 @@ class RowIteratorTest extends TestCase foreach ($iterator as $key => $row) { ++$counter; self::assertEquals($rowIndexResult++, $key); - self::assertInstanceOf(Row::class, $row); } self::assertCount($counter, self::CELL_VALUES); $spreadsheet->disconnectWorksheets(); @@ -61,7 +59,6 @@ class RowIteratorTest extends TestCase foreach ($iterator as $key => $row) { ++$counter; self::assertEquals($rowIndexResult++, $key); - self::assertInstanceOf(Row::class, $row); } self::assertSame(3, $counter); $spreadsheet->disconnectWorksheets(); diff --git a/tests/PhpSpreadsheetTests/Worksheet/RowTest.php b/tests/PhpSpreadsheetTests/Worksheet/RowTest.php index 810e763d4..d7dce510a 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/RowTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/RowTest.php @@ -6,7 +6,6 @@ namespace PhpOffice\PhpSpreadsheetTests\Worksheet; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Worksheet\Row; -use PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator; use PHPUnit\Framework\TestCase; class RowTest extends TestCase @@ -16,7 +15,6 @@ class RowTest extends TestCase $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $row = new Row($sheet); - self::assertInstanceOf(Row::class, $row); $rowIndex = $row->getRowIndex(); self::assertEquals(1, $rowIndex); $spreadsheet->disconnectWorksheets(); @@ -27,7 +25,6 @@ class RowTest extends TestCase $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $row = new Row($sheet, 5); - self::assertInstanceOf(Row::class, $row); $rowIndex = $row->getRowIndex(); self::assertEquals(5, $rowIndex); $spreadsheet->disconnectWorksheets(); @@ -39,7 +36,7 @@ class RowTest extends TestCase $sheet = $spreadsheet->getActiveSheet(); $row = new Row($sheet); $cellIterator = $row->getCellIterator(); - self::assertInstanceOf(RowCellIterator::class, $cellIterator); + self::assertSame(1, $cellIterator->getCurrentColumnIndex()); $spreadsheet->disconnectWorksheets(); } @@ -49,7 +46,7 @@ class RowTest extends TestCase $sheet = $spreadsheet->getActiveSheet(); $row = new Row($sheet); $cellIterator = $row->getColumnIterator(); - self::assertInstanceOf(RowCellIterator::class, $cellIterator); + self::assertSame(1, $cellIterator->getCurrentColumnIndex()); $spreadsheet->disconnectWorksheets(); } } diff --git a/tests/PhpSpreadsheetTests/Worksheet/Table/ColumnTest.php b/tests/PhpSpreadsheetTests/Worksheet/Table/ColumnTest.php index be184af1b..9dbced10a 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/Table/ColumnTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/Table/ColumnTest.php @@ -52,7 +52,6 @@ class ColumnTest extends SetupTeardown $expectedResult = 'G'; $result = $column->setColumnIndex($expectedResult); - self::assertInstanceOf(Column::class, $result); $result = $result->getColumnIndex(); self::assertEquals($expectedResult, $result); @@ -64,22 +63,18 @@ class ColumnTest extends SetupTeardown $column = $table->getColumn('H'); $result = $column->setShowFilterButton(false); - self::assertInstanceOf(Column::class, $result); self::assertFalse($column->getShowFilterButton()); $label = 'Total'; $result = $column->setTotalsRowLabel($label); - self::assertInstanceOf(Column::class, $result); self::assertEquals($label, $column->getTotalsRowLabel()); $function = 'sum'; $result = $column->setTotalsRowFunction($function); - self::assertInstanceOf(Column::class, $result); self::assertEquals($function, $column->getTotalsRowFunction()); $formula = '=SUM(Sales_Data[[#This Row],[Q1]:[Q4]])'; $result = $column->setColumnFormula($formula); - self::assertInstanceOf(Column::class, $result); self::assertEquals($formula, $column->getColumnFormula()); } diff --git a/tests/PhpSpreadsheetTests/Worksheet/Table/TableStyleTest.php b/tests/PhpSpreadsheetTests/Worksheet/Table/TableStyleTest.php index a84da3814..e76e31b66 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/Table/TableStyleTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/Table/TableStyleTest.php @@ -17,23 +17,18 @@ class TableStyleTest extends SetupTeardown $style = $table->getStyle(); $result = $style->setTheme(TableStyle::TABLE_STYLE_DARK1); - self::assertInstanceOf(TableStyle::class, $result); self::assertEquals(TableStyle::TABLE_STYLE_DARK1, $style->getTheme()); $result = $style->setShowFirstColumn(true); - self::assertInstanceOf(TableStyle::class, $result); self::assertTrue($style->getShowFirstColumn()); $result = $style->setShowLastColumn(true); - self::assertInstanceOf(TableStyle::class, $result); self::assertTrue($style->getShowLastColumn()); $result = $style->setShowRowStripes(true); - self::assertInstanceOf(TableStyle::class, $result); self::assertTrue($style->getShowRowStripes()); $result = $style->setShowColumnStripes(true); - self::assertInstanceOf(TableStyle::class, $result); self::assertTrue($style->getShowColumnStripes()); } diff --git a/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php b/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php index 075eb451a..2f308fe25 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php @@ -11,7 +11,7 @@ use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException; use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter; use PhpOffice\PhpSpreadsheet\Worksheet\Table; use PhpOffice\PhpSpreadsheet\Worksheet\Table\Column; -use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; class TableTest extends SetupTeardown { @@ -27,13 +27,12 @@ class TableTest extends SetupTeardown self::assertEquals($expectedResult, $result); } - #[\PHPUnit\Framework\Attributes\DataProvider('validTableNamesProvider')] + #[DataProvider('validTableNamesProvider')] public function testValidTableNames(string $name, string $expected): void { $table = new Table(self::INITIAL_RANGE); $result = $table->setName($name); - self::assertInstanceOf(Table::class, $result); self::assertEquals($expected, $table->getName()); } @@ -50,7 +49,7 @@ class TableTest extends SetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('invalidTableNamesProvider')] + #[DataProvider('invalidTableNamesProvider')] public function testInvalidTableNames(string $name): void { $table = new Table(self::INITIAL_RANGE); @@ -114,11 +113,9 @@ class TableTest extends SetupTeardown $table = new Table(self::INITIAL_RANGE); $result = $table->setShowHeaderRow(false); - self::assertInstanceOf(Table::class, $result); self::assertFalse($table->getShowHeaderRow()); $result = $table->setShowTotalsRow(true); - self::assertInstanceOf(Table::class, $result); self::assertTrue($table->getShowTotalsRow()); } @@ -138,7 +135,7 @@ class TableTest extends SetupTeardown $sheet2 = $spreadsheet->createSheet(); // Setters return the instance to implement the fluent interface $result = $table->setWorksheet($sheet2); - self::assertInstanceOf(Table::class, $result); + self::assertSame(self::INITIAL_RANGE, $result->getRange()); } public function testGetRange(): void @@ -159,7 +156,6 @@ class TableTest extends SetupTeardown $table = new Table(self::INITIAL_RANGE); $result = $table->setRange($fullRange); - self::assertInstanceOf(Table::class, $result); self::assertEquals($actualRange, $table->getRange()); } @@ -190,14 +186,13 @@ class TableTest extends SetupTeardown // Setters return the instance to implement the fluent interface $result = $table->setRange(''); - self::assertInstanceOf(Table::class, $result); // Result should be a clear range $result = $table->getRange(); self::assertEquals($expectedResult, $result); } - #[\PHPUnit\Framework\Attributes\DataProvider('invalidTableRangeProvider')] + #[DataProvider('invalidTableRangeProvider')] public function testSetRangeInvalidRange(string $range): void { $this->expectException(PhpSpreadsheetException::class); @@ -220,7 +215,6 @@ class TableTest extends SetupTeardown // There should be no columns yet defined $table = new Table(self::INITIAL_RANGE); $result = $table->getColumns(); - self::assertIsArray($result); self::assertCount(0, $result); } @@ -318,15 +312,12 @@ class TableTest extends SetupTeardown // Setters return the instance to implement the fluent interface $result = $table->setColumn($expectedResult); - self::assertInstanceOf(Table::class, $result); $result = $table->getColumns(); // Result should be an array of \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\Table\Column // objects for each column we set indexed by the column ID - self::assertIsArray($result); self::assertCount(1, $result); self::assertArrayHasKey($expectedResult, $result); - self::assertInstanceOf(Column::class, $result[$expectedResult]); } public function testSetInvalidColumnWithString(): void @@ -346,15 +337,12 @@ class TableTest extends SetupTeardown // Setters return the instance to implement the fluent interface $result = $table->setColumn($columnObject); - self::assertInstanceOf(Table::class, $result); $result = $table->getColumns(); // Result should be an array of \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\Table\Column // objects for each column we set indexed by the column ID - self::assertIsArray($result); self::assertCount(1, $result); self::assertArrayHasKey($expectedResult, $result); - self::assertInstanceOf(Column::class, $result[$expectedResult]); } public function testSetInvalidColumnWithObject(): void @@ -379,11 +367,9 @@ class TableTest extends SetupTeardown $result = $table->getColumns(); // Result should be an array of \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\Table\Column // objects for each column we set indexed by the column ID - self::assertIsArray($result); self::assertCount(count($columnIndexes), $result); foreach ($columnIndexes as $columnIndex) { self::assertArrayHasKey($columnIndex, $result); - self::assertInstanceOf(Column::class, $result[$columnIndex]); } $table->setRange(''); @@ -405,7 +391,7 @@ class TableTest extends SetupTeardown // get a \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\Table\Column object returned foreach ($columnIndexes as $columnIndex) { $result = $table->getColumn($columnIndex); - self::assertInstanceOf(Column::class, $result); + self::assertSame($columnIndex, $result->getColumnIndex()); } } @@ -423,7 +409,6 @@ class TableTest extends SetupTeardown // get a \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\Table\Column object returned foreach ($columnIndexes as $columnIndex => $columnID) { $result = $table->getColumnByOffset($columnIndex); - self::assertInstanceOf(Column::class, $result); self::assertEquals($result->getColumnIndex(), $columnID); } } @@ -434,7 +419,7 @@ class TableTest extends SetupTeardown // If we request a specific column by its column ID, we should // get a \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\Table\Column object returned $result = $table->getColumn('K'); - self::assertInstanceOf(Column::class, $result); + self::assertSame('K', $result->getColumnIndex()); } public function testGetColumnWithoutRangeSet(): void @@ -459,7 +444,6 @@ class TableTest extends SetupTeardown // Setters return the instance to implement the fluent interface $result = $table->setRange(''); - self::assertInstanceOf(Table::class, $result); // Range should be cleared $result = $table->getRange(); @@ -467,7 +451,6 @@ class TableTest extends SetupTeardown // Column array should be cleared $result = $table->getColumns(); - self::assertIsArray($result); self::assertCount(0, $result); } @@ -489,7 +472,6 @@ class TableTest extends SetupTeardown // Setters return the instance to implement the fluent interface $result = $table->setRange($expectedResult); - self::assertInstanceOf(Table::class, $result); // Range should be correctly set $result = $table->getRange(); @@ -498,7 +480,6 @@ class TableTest extends SetupTeardown // Only columns that existed in the original range and that // still fall within the new range should be retained $result = $table->getColumns(); - self::assertIsArray($result); self::assertCount(count($columnIndexes1), $result); } @@ -514,25 +495,17 @@ class TableTest extends SetupTeardown } $result = clone $table; - self::assertInstanceOf(Table::class, $result); self::assertSame($table->getRange(), $result->getRange()); self::assertNull($result->getWorksheet()); self::assertNotNull($table->getWorksheet()); - self::assertInstanceOf(Worksheet::class, $table->getWorksheet()); $tableColumns = $table->getColumns(); $resultColumns = $result->getColumns(); - self::assertIsArray($tableColumns); - self::assertIsArray($resultColumns); self::assertCount(2, $tableColumns); self::assertCount(2, $resultColumns); self::assertArrayHasKey('L', $tableColumns); self::assertArrayHasKey('L', $resultColumns); self::assertArrayHasKey('M', $tableColumns); self::assertArrayHasKey('M', $resultColumns); - self::assertInstanceOf(Column::class, $tableColumns['L']); - self::assertInstanceOf(Column::class, $resultColumns['L']); - self::assertInstanceOf(Column::class, $tableColumns['M']); - self::assertInstanceOf(Column::class, $resultColumns['M']); } public function testNoWorksheet(): void diff --git a/tests/PhpSpreadsheetTests/Worksheet/Worksheet2Test.php b/tests/PhpSpreadsheetTests/Worksheet/Worksheet2Test.php index e6768dc9e..e918f6c64 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/Worksheet2Test.php +++ b/tests/PhpSpreadsheetTests/Worksheet/Worksheet2Test.php @@ -95,11 +95,10 @@ class Worksheet2Test extends TestCase self::assertSame('D3', $selected); self::assertSame('bottomLeft', $pane); $worksheet->unfreezePane(); - self::assertNull($this->getPane($worksheet)); $freeze = $this->getPane($worksheet); + self::assertNull($freeze); $pane = $worksheet->getActivePane(); $selected = $worksheet->getSelectedCells(); - self::assertEmpty($freeze); self::assertEquals('', $pane); self::assertSame('D3', $selected); $spreadsheet->disconnectWorksheets();