diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index 98f36cde0b..c88656b4a0 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -4250,7 +4250,7 @@ private function internalParseFormula($formula, ?Cell $cell = null) } elseif ($expectedArgumentCount != '*') { $isOperandOrFunction = preg_match('/(\d*)([-+,])(\d*)/', $expectedArgumentCount, $argMatch); self::doNothing($isOperandOrFunction); - switch ($argMatch[2]) { + switch ($argMatch[2] ?? '') { case '+': if ($argumentCount < $argMatch[1]) { $argumentCountError = true; diff --git a/src/PhpSpreadsheet/Reader/Xlsx.php b/src/PhpSpreadsheet/Reader/Xlsx.php index 310fef74f8..ef2f48af0a 100644 --- a/src/PhpSpreadsheet/Reader/Xlsx.php +++ b/src/PhpSpreadsheet/Reader/Xlsx.php @@ -134,7 +134,7 @@ private function loadZip(string $filename, string $ns = '', bool $replaceUnclose if ($replaceUnclosedBr) { $contents = str_replace('
', '
', $contents); } - $rels = simplexml_load_string( + $rels = @simplexml_load_string( $this->getSecurityScannerOrThrow()->scan($contents), 'SimpleXMLElement', Settings::getLibXmlLoaderOptions(), diff --git a/tests/PhpSpreadsheetTests/Calculation/DefinedNamesCalculationTest.php b/tests/PhpSpreadsheetTests/Calculation/DefinedNamesCalculationTest.php index d0a5aacb6b..4f450f57c5 100644 --- a/tests/PhpSpreadsheetTests/Calculation/DefinedNamesCalculationTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/DefinedNamesCalculationTest.php @@ -71,7 +71,7 @@ public function testNamedFormulaeCalculationsWithAdjustedRateValue(string $cellA self::assertSame($expectedValue, $calculatedCellValue, "Failed calculation for cell {$cellAddress}"); } - public function namedRangeCalculationTest1(): array + public static function namedRangeCalculationTest1(): array { return [ ['C4', 56.25], @@ -84,7 +84,7 @@ public function namedRangeCalculationTest1(): array ]; } - public function namedRangeCalculationTest2(): array + public static function namedRangeCalculationTest2(): array { return [ ['C4', 93.75], diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DAverageTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DAverageTest.php index b1756b2a8e..777469525c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DAverageTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DAverageTest.php @@ -35,12 +35,12 @@ public function testDAverageAsWorksheetFormula($expectedResult, array $database, self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - public function providerDAverage(): array + public static function providerDAverage(): array { return [ [ 12, - $this->database1(), + self::database1(), 'Yield', [ ['Tree', 'Height'], @@ -49,7 +49,7 @@ public function providerDAverage(): array ], [ 268333.333333333333, - $this->database2(), + self::database2(), 'Sales', [ ['Quarter', 'Sales Rep.'], @@ -58,7 +58,7 @@ public function providerDAverage(): array ], [ 372500, - $this->database2(), + self::database2(), 'Sales', [ ['Quarter', 'Area'], @@ -67,25 +67,25 @@ public function providerDAverage(): array ], 'numeric column, in this case referring to age' => [ 13, - $this->database1(), + self::database1(), 3, - $this->database1(), + self::database1(), ], 'null field' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), null, - $this->database1(), + self::database1(), ], 'field unknown column' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), 'xyz', - $this->database1(), + self::database1(), ], 'multiple criteria, omit equal sign' => [ 10.5, - $this->database1(), + self::database1(), 'Yield', [ ['Tree', 'Height'], @@ -95,7 +95,7 @@ public function providerDAverage(): array ], 'multiple criteria for same field' => [ 10, - $this->database1(), + self::database1(), 'Yield', [ ['Tree', 'Height', 'Age', 'Height'], @@ -108,15 +108,15 @@ public function providerDAverage(): array content to return #VALUE! as an invalid name would */ 'field column number too high' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), 99, - $this->database1(), + self::database1(), ], 'field column number too low' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), 0, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountATest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountATest.php index 2fd1172311..0bbd0372af 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountATest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountATest.php @@ -37,12 +37,12 @@ public function testDCountAAsWorksheetFormula($expectedResult, $database, $field self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - public function providerDCountA(): array + public static function providerDCountA(): array { return [ [ 1, - $this->database1(), + self::database1(), 'Profit', [ ['Tree', 'Height', 'Height'], @@ -51,7 +51,7 @@ public function providerDCountA(): array ], [ 2, - $this->database3(), + self::database3(), 'Score', [ ['Subject', 'Gender'], @@ -60,7 +60,7 @@ public function providerDCountA(): array ], [ 1, - $this->database3(), + self::database3(), 'Score', [ ['Subject', 'Gender'], @@ -69,7 +69,7 @@ public function providerDCountA(): array ], [ 3, - $this->database3(), + self::database3(), 'Score', [ ['Subject', 'Score'], @@ -78,7 +78,7 @@ public function providerDCountA(): array ], 'invalid field name' => [ ExcelError::VALUE(), - $this->database3(), + self::database3(), 'Scorex', [ ['Subject', 'Score'], diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountTest.php index 9ed79801c7..a986e70048 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DCountTest.php @@ -37,7 +37,7 @@ public function testDCountAsWorksheetFormula($expectedResult, $database, $field, self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - private function database4(): array + private static function database4(): array { return [ ['Status', 'Value'], @@ -52,12 +52,12 @@ private function database4(): array ]; } - public function providerDCount(): array + public static function providerDCount(): array { return [ [ 1, - $this->database1(), + self::database1(), 'Age', [ ['Tree', 'Height', 'Height'], @@ -66,7 +66,7 @@ public function providerDCount(): array ], [ 1, - $this->database3(), + self::database3(), 'Score', [ ['Subject', 'Gender'], @@ -75,7 +75,7 @@ public function providerDCount(): array ], [ 1, - $this->database3(), + self::database3(), 'Score', [ ['Subject', 'Gender'], @@ -84,7 +84,7 @@ public function providerDCount(): array ], [ 3, - $this->database4(), + self::database4(), 'Value', [ ['Status'], @@ -93,7 +93,7 @@ public function providerDCount(): array ], [ 5, - $this->database4(), + self::database4(), 'Value', [ ['Status'], @@ -102,13 +102,13 @@ public function providerDCount(): array ], 'field column number okay' => [ 0, - $this->database1(), + self::database1(), 1, - $this->database1(), + self::database1(), ], 'omitted field name' => [ ExcelError::VALUE(), - $this->database3(), + self::database3(), null, [ ['Subject', 'Score'], @@ -121,15 +121,15 @@ public function providerDCount(): array content to return #VALUE! as an invalid name would */ 'field column number too high' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), 99, - $this->database1(), + self::database1(), ], 'field column number too low' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), 0, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DGetTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DGetTest.php index 5b0ce9bc6d..24394c7d9a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DGetTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DGetTest.php @@ -37,12 +37,12 @@ public function testDGetAsWorksheetFormula($expectedResult, $database, $field, $ self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - public function providerDGet(): array + public static function providerDGet(): array { return [ [ ExcelError::NAN(), - $this->database1(), + self::database1(), 'Yield', [ ['Tree'], @@ -52,7 +52,7 @@ public function providerDGet(): array ], [ 10, - $this->database1(), + self::database1(), 'Yield', [ ['Tree', 'Height', 'Height'], @@ -62,7 +62,7 @@ public function providerDGet(): array ], [ 188000, - $this->database2(), + self::database2(), 'Sales', [ ['Sales Rep.', 'Quarter'], @@ -71,7 +71,7 @@ public function providerDGet(): array ], [ ExcelError::NAN(), - $this->database2(), + self::database2(), 'Sales', [ ['Area', 'Quarter'], @@ -80,9 +80,9 @@ public function providerDGet(): array ], 'omitted field name' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), null, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMaxTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMaxTest.php index d06e4972e1..a4dc9f9e74 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMaxTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMaxTest.php @@ -37,12 +37,12 @@ public function testDMaxAsWorksheetFormula($expectedResult, $database, $field, $ self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - public function providerDMax(): array + public static function providerDMax(): array { return [ [ 96, - $this->database1(), + self::database1(), 'Profit', [ ['Tree', 'Height', 'Height'], @@ -52,7 +52,7 @@ public function providerDMax(): array ], [ 340000, - $this->database2(), + self::database2(), 'Sales', [ ['Quarter', 'Area'], @@ -61,7 +61,7 @@ public function providerDMax(): array ], [ 460000, - $this->database2(), + self::database2(), 'Sales', [ ['Sales Rep.', 'Quarter'], @@ -70,15 +70,15 @@ public function providerDMax(): array ], 'omitted field name' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), null, - $this->database1(), + self::database1(), ], 'field column number okay' => [ 18, - $this->database1(), + self::database1(), 2, - $this->database1(), + self::database1(), ], /* Excel seems to return #NAME? when column number is too high or too low. This makes so little sense @@ -86,15 +86,15 @@ public function providerDMax(): array content to return #VALUE! as an invalid name would */ 'field column number too high' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), 99, - $this->database1(), + self::database1(), ], 'field column number too low' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), 0, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMinTest.php index d49004eab7..c3257d2722 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMinTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DMinTest.php @@ -37,12 +37,12 @@ public function testDMinAsWorksheetFormula($expectedResult, $database, $field, $ self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - public function providerDMin(): array + public static function providerDMin(): array { return [ [ 75, - $this->database1(), + self::database1(), 'Profit', [ ['Tree', 'Height', 'Height'], @@ -52,7 +52,7 @@ public function providerDMin(): array ], [ 0.48, - $this->database3(), + self::database3(), 'Score', [ ['Subject', 'Age'], @@ -61,7 +61,7 @@ public function providerDMin(): array ], [ 0.55, - $this->database3(), + self::database3(), 'Score', [ ['Subject', 'Gender'], @@ -70,15 +70,15 @@ public function providerDMin(): array ], 'omitted field name' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), null, - $this->database1(), + self::database1(), ], 'field column number okay' => [ 8, - $this->database1(), + self::database1(), 2, - $this->database1(), + self::database1(), ], /* Excel seems to return #NAME? when column number is too high or too low. This makes so little sense @@ -86,15 +86,15 @@ public function providerDMin(): array content to return #VALUE! as an invalid name would */ 'field column number too high' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), 99, - $this->database1(), + self::database1(), ], 'field column number too low' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), 0, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DProductTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DProductTest.php index dc52d73eaa..6aca35b62c 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DProductTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DProductTest.php @@ -38,7 +38,7 @@ public function testDProductAsWorksheetFormula($expectedResult, $database, $fiel self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - private function database5(): array + private static function database5(): array { return [ ['Name', 'Date', 'Test', 'Score'], @@ -57,12 +57,12 @@ private function database5(): array ]; } - public function providerDProduct(): array + public static function providerDProduct(): array { return [ [ 800.0, - $this->database1(), + self::database1(), 'Yield', [ ['Tree', 'Height', 'Height'], @@ -72,7 +72,7 @@ public function providerDProduct(): array ], [ 36.0, - $this->database5(), + self::database5(), 'Score', [ ['Name', 'Date'], @@ -81,7 +81,7 @@ public function providerDProduct(): array ], [ 8.0, - $this->database5(), + self::database5(), 'Score', [ ['Test', 'Date'], @@ -90,9 +90,9 @@ public function providerDProduct(): array ], 'omitted field name' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), null, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevPTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevPTest.php index 9fb869c49e..1c73535732 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevPTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevPTest.php @@ -37,12 +37,12 @@ public function testDStDevPAsWorksheetFormula($expectedResult, $database, $field self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - public function providerDStDevP(): array + public static function providerDStDevP(): array { return [ [ 2.653299832284, - $this->database1(), + self::database1(), 'Yield', [ ['Tree'], @@ -52,7 +52,7 @@ public function providerDStDevP(): array ], [ 0.085244745684, - $this->database3FilledIn(), + self::database3FilledIn(), 'Score', [ ['Subject', 'Gender'], @@ -61,7 +61,7 @@ public function providerDStDevP(): array ], [ 0.160623784042, - $this->database3FilledIn(), + self::database3FilledIn(), 'Score', [ ['Subject', 'Age'], @@ -70,7 +70,7 @@ public function providerDStDevP(): array ], [ 0.01, - $this->database3(), + self::database3(), 'Score', [ ['Subject', 'Gender'], @@ -79,7 +79,7 @@ public function providerDStDevP(): array ], [ 0, - $this->database3(), + self::database3(), 'Score', [ ['Subject', 'Age'], @@ -88,9 +88,9 @@ public function providerDStDevP(): array ], 'omitted field name' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), null, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevTest.php index 55fc5bdfee..7698e73ec4 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DStDevTest.php @@ -37,12 +37,12 @@ public function testDStDevAsWorksheetFormula($expectedResult, $database, $field, self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - public function providerDStDev(): array + public static function providerDStDev(): array { return [ [ 2.966479394838, - $this->database1(), + self::database1(), 'Yield', [ ['Tree'], @@ -52,7 +52,7 @@ public function providerDStDev(): array ], [ 0.104403065089, - $this->database3FilledIn(), + self::database3FilledIn(), 'Score', [ ['Subject', 'Gender'], @@ -61,7 +61,7 @@ public function providerDStDev(): array ], [ 0.196723155729, - $this->database3FilledIn(), + self::database3FilledIn(), 'Score', [ ['Subject', 'Age'], @@ -70,9 +70,9 @@ public function providerDStDev(): array ], 'omitted field name' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), null, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DSumTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DSumTest.php index 4525d3edff..6f16c3e658 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DSumTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DSumTest.php @@ -37,12 +37,12 @@ public function testDSumAsWorksheetFormula($expectedResult, $database, $field, $ self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - public function providerDSum(): array + public static function providerDSum(): array { return [ [ 225, - $this->database1(), + self::database1(), 'Profit', [ ['Tree'], @@ -51,7 +51,7 @@ public function providerDSum(): array ], [ 247.8, - $this->database1(), + self::database1(), 'Profit', [ ['Tree', 'Height', 'Height'], @@ -61,7 +61,7 @@ public function providerDSum(): array ], [ 1210000, - $this->database2(), + self::database2(), 'Sales', [ ['Quarter', 'Area'], @@ -70,7 +70,7 @@ public function providerDSum(): array ], [ 710000, - $this->database2(), + self::database2(), 'Sales', [ ['Quarter', 'Sales Rep.'], @@ -79,7 +79,7 @@ public function providerDSum(): array ], [ 705000, - $this->database2(), + self::database2(), 'Sales', [ ['Quarter', 'Sales Rep.'], @@ -88,9 +88,9 @@ public function providerDSum(): array ], 'omitted field name' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), null, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarPTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarPTest.php index 80db8f5638..3e12fd0a6a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarPTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarPTest.php @@ -37,12 +37,12 @@ public function testDVarPAsWorksheetFormula($expectedResult, $database, $field, self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - public function providerDVarP(): array + public static function providerDVarP(): array { return [ [ 7.04, - $this->database1(), + self::database1(), 'Yield', [ ['Tree'], @@ -52,7 +52,7 @@ public function providerDVarP(): array ], [ 0.025622222222, - $this->database3FilledIn(), + self::database3FilledIn(), 'Score', [ ['Subject', 'Gender'], @@ -61,7 +61,7 @@ public function providerDVarP(): array ], [ 0.011622222222, - $this->database3FilledIn(), + self::database3FilledIn(), 'Score', [ ['Subject', 'Age'], @@ -70,9 +70,9 @@ public function providerDVarP(): array ], 'Omitted field name' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), null, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarTest.php index 46cc6eead1..da8c31c3d8 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/DVarTest.php @@ -37,12 +37,12 @@ public function testDVarAsWorksheetFormula($expectedResult, $database, $field, $ self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12); } - public function providerDVar(): array + public static function providerDVar(): array { return [ [ 8.8, - $this->database1(), + self::database1(), 'Yield', [ ['Tree'], @@ -52,7 +52,7 @@ public function providerDVar(): array ], [ 0.038433333333, - $this->database3FilledIn(), + self::database3FilledIn(), 'Score', [ ['Subject', 'Gender'], @@ -61,7 +61,7 @@ public function providerDVar(): array ], [ 0.017433333333, - $this->database3FilledIn(), + self::database3FilledIn(), 'Score', [ ['Subject', 'Age'], @@ -70,9 +70,9 @@ public function providerDVar(): array ], 'omitted field name' => [ ExcelError::VALUE(), - $this->database1(), + self::database1(), null, - $this->database1(), + self::database1(), ], ]; } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/SetupTeardownDatabases.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/SetupTeardownDatabases.php index d442a63357..9c79d9ae13 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Database/SetupTeardownDatabases.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Database/SetupTeardownDatabases.php @@ -37,7 +37,7 @@ protected function tearDown(): void Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); } - protected function database1(): array + protected static function database1(): array { return [ ['Tree', 'Height', 'Age', 'Yield', 'Profit'], @@ -50,7 +50,7 @@ protected function database1(): array ]; } - protected function database2(): array + protected static function database2(): array { return [ ['Quarter', 'Area', 'Sales Rep.', 'Sales'], @@ -73,7 +73,7 @@ protected function database2(): array ]; } - protected function database3(): array + protected static function database3(): array { return [ ['Name', 'Gender', 'Age', 'Subject', 'Score'], @@ -92,7 +92,7 @@ protected function database3(): array ]; } - protected function database3FilledIn(): array + protected static function database3FilledIn(): array { // same as database3 except two omitted scores are filled in return [ diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortByTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortByTest.php index 345f732bdf..616ba93678 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortByTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortByTest.php @@ -30,7 +30,7 @@ public function testSortByWithArgumentErrorReturns($sortIndex, $sortOrder = 1): self::assertSame(ExcelError::VALUE(), $result); } - public function providerSortWithScalarArgumentErrorReturns(): array + public static function providerSortWithScalarArgumentErrorReturns(): array { return [ 'Non-array sortIndex' => ['A', 1], @@ -51,7 +51,7 @@ public function testSortByRow(array $expectedResult, array $matrix, ...$args): v self::assertSame($expectedResult, $result); } - public function providerSortByRow(): array + public static function providerSortByRow(): array { return [ 'Simple sort by age' => [ @@ -65,8 +65,8 @@ public function providerSortByRow(): array ['Hector', 66], ['Sal', 73], ], - $this->sampleDataForSimpleSort(), - array_column($this->sampleDataForSimpleSort(), 1), + self::sampleDataForSimpleSort(), + array_column(self::sampleDataForSimpleSort(), 1), ], 'Simple sort by name' => [ [ @@ -79,8 +79,8 @@ public function providerSortByRow(): array ['Tom', 52], ['Xi', 19], ], - $this->sampleDataForSimpleSort(), - array_column($this->sampleDataForSimpleSort(), 0), + self::sampleDataForSimpleSort(), + array_column(self::sampleDataForSimpleSort(), 0), ], 'Row vector' => [ [ @@ -93,7 +93,7 @@ public function providerSortByRow(): array ['Tom', 52], ['Xi', 19], ], - $this->sampleDataForSimpleSort(), + self::sampleDataForSimpleSort(), ['Tom', 'Fred', 'Amy', 'Sal', 'Fritz', 'Srivan', 'Xi', 'Hector'], ], 'Column vector' => [ @@ -107,7 +107,7 @@ public function providerSortByRow(): array ['Tom', 52], ['Xi', 19], ], - $this->sampleDataForSimpleSort(), + self::sampleDataForSimpleSort(), [['Tom'], ['Fred'], ['Amy'], ['Sal'], ['Fritz'], ['Srivan'], ['Xi'], ['Hector']], ], 'Sort by region asc, name asc' => [ @@ -121,10 +121,10 @@ public function providerSortByRow(): array ['West', 'Fred', 65], ['West', 'Srivan', 39], ], - $this->sampleDataForMultiSort(), - array_column($this->sampleDataForMultiSort(), 0), + self::sampleDataForMultiSort(), + array_column(self::sampleDataForMultiSort(), 0), Sort::ORDER_ASCENDING, - array_column($this->sampleDataForMultiSort(), 1), + array_column(self::sampleDataForMultiSort(), 1), ], 'Sort by region asc, age desc' => [ [ @@ -137,16 +137,16 @@ public function providerSortByRow(): array ['West', 'Fred', 65], ['West', 'Srivan', 39], ], - $this->sampleDataForMultiSort(), - array_column($this->sampleDataForMultiSort(), 0), + self::sampleDataForMultiSort(), + array_column(self::sampleDataForMultiSort(), 0), Sort::ORDER_ASCENDING, - array_column($this->sampleDataForMultiSort(), 2), + array_column(self::sampleDataForMultiSort(), 2), Sort::ORDER_DESCENDING, ], ]; } - private function sampleDataForSimpleSort(): array + private static function sampleDataForSimpleSort(): array { return [ ['Tom', 52], @@ -160,7 +160,7 @@ private function sampleDataForSimpleSort(): array ]; } - private function sampleDataForMultiSort(): array + private static function sampleDataForMultiSort(): array { return [ ['North', 'Amy', 22], diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortTest.php index bd120e301c..1cd2a138c8 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortTest.php @@ -30,7 +30,7 @@ public function testSortWithScalarArgumentErrorReturns($sortIndex, $sortOrder = self::assertSame(ExcelError::VALUE(), $result); } - public function providerSortWithScalarArgumentErrorReturns(): array + public static function providerSortWithScalarArgumentErrorReturns(): array { return [ 'Negative sortIndex' => [-1, -1], @@ -58,17 +58,17 @@ public function testSortByRow(array $expectedResult, array $matrix, int $sortInd self::assertSame($expectedResult, $result); } - public function providerSortByRow(): array + public static function providerSortByRow(): array { return [ [ [[142], [378], [404], [445], [483], [622], [650], [691], [783], [961]], - $this->sampleDataForRow(), + self::sampleDataForRow(), 1, ], [ [[961], [783], [691], [650], [622], [483], [445], [404], [378], [142]], - $this->sampleDataForRow(), + self::sampleDataForRow(), 1, Sort::ORDER_DESCENDING, ], @@ -89,7 +89,7 @@ public function testSortByRowMultiLevel(array $expectedResult, array $matrix, ar self::assertSame($expectedResult, $result); } - public function providerSortByRowMultiLevel(): array + public static function providerSortByRowMultiLevel(): array { return [ [ @@ -107,7 +107,7 @@ public function providerSortByRowMultiLevel(): array ['West', 'Lemons', 34], ['West', 'Oranges', 25], ], - $this->sampleDataForMultiRow(), + self::sampleDataForMultiRow(), [1, 2], ], [ @@ -125,7 +125,7 @@ public function providerSortByRowMultiLevel(): array ['West', 'Apples', 30], ['West', 'Lemons', 34], ], - $this->sampleDataForMultiRow(), + self::sampleDataForMultiRow(), [1, 3], ], [ @@ -143,7 +143,7 @@ public function providerSortByRowMultiLevel(): array ['North', 'Peaches', 25], ['South', 'Pears', 40], ], - $this->sampleDataForMultiRow(), + self::sampleDataForMultiRow(), [2, 3], ], ]; @@ -158,32 +158,32 @@ public function testSortByColumn(array $expectedResult, array $matrix, int $sort self::assertSame($expectedResult, $result); } - public function providerSortByColumn(): array + public static function providerSortByColumn(): array { return [ [ [[142, 378, 404, 445, 483, 622, 650, 691, 783, 961]], - $this->sampleDataForColumn(), + self::sampleDataForColumn(), 1, Sort::ORDER_ASCENDING, ], [ [[961, 783, 691, 650, 622, 483, 445, 404, 378, 142]], - $this->sampleDataForColumn(), + self::sampleDataForColumn(), 1, Sort::ORDER_DESCENDING, ], ]; } - public function sampleDataForRow(): array + public static function sampleDataForRow(): array { return [ [622], [961], [691], [445], [378], [483], [650], [783], [142], [404], ]; } - public function sampleDataForMultiRow(): array + public static function sampleDataForMultiRow(): array { return [ ['South', 'Pears', 40], @@ -201,7 +201,7 @@ public function sampleDataForMultiRow(): array ]; } - public function sampleDataForColumn(): array + public static function sampleDataForColumn(): array { return [ [622, 961, 691, 445, 378, 483, 650, 783, 142, 404], diff --git a/tests/PhpSpreadsheetTests/Cell/CellTest.php b/tests/PhpSpreadsheetTests/Cell/CellTest.php index 2ed095bfe1..2008153744 100644 --- a/tests/PhpSpreadsheetTests/Cell/CellTest.php +++ b/tests/PhpSpreadsheetTests/Cell/CellTest.php @@ -301,7 +301,7 @@ public function testAppliedStyleSingleCell(string $cellAddress, string $fillStyl } } - public function appliedStyling(): array + public static function appliedStyling(): array { return [ 'A1 - Conditional with Match' => ['A1', Fill::FILL_SOLID, Color::COLOR_RED], diff --git a/tests/PhpSpreadsheetTests/Custom/ComplexAssert.php b/tests/PhpSpreadsheetTests/Custom/ComplexAssert.php index 0b3f18f4c4..0341041279 100644 --- a/tests/PhpSpreadsheetTests/Custom/ComplexAssert.php +++ b/tests/PhpSpreadsheetTests/Custom/ComplexAssert.php @@ -15,6 +15,11 @@ class ComplexAssert extends TestCase /** @var float */ private $delta = 0.0; + public function __construct() + { + parent::__construct('complexAssert'); + } + /** * @param mixed $expected * @param mixed $actual diff --git a/tests/PhpSpreadsheetTests/Helper/SampleTest.php b/tests/PhpSpreadsheetTests/Helper/SampleTest.php index 384011e83d..387597f7d1 100644 --- a/tests/PhpSpreadsheetTests/Helper/SampleTest.php +++ b/tests/PhpSpreadsheetTests/Helper/SampleTest.php @@ -16,16 +16,14 @@ class SampleTest extends TestCase */ public function testSample(string $sample): void { - // Suppress output to console - $this->setOutputCallback(function (): void { - }); - + ob_start(); require $sample; + ob_end_clean(); self::assertTrue(true); } - public function providerSample(): array + public static function providerSample(): array { $skipped = [ ]; diff --git a/tests/PhpSpreadsheetTests/Reader/Html/HtmlLibxmlTest.php b/tests/PhpSpreadsheetTests/Reader/Html/HtmlLibxmlTest.php new file mode 100644 index 0000000000..d5f5044aa0 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Html/HtmlLibxmlTest.php @@ -0,0 +1,46 @@ +useErrors = libxml_use_internal_errors(true); + } + + protected function tearDown(): void + { + libxml_use_internal_errors($this->useErrors); + } + + public function testLoadInvalidString(): void + { + $html = ''; + (new Html())->loadFromString($html); + self::assertNotEmpty(libxml_get_errors()); + } + + public function testLoadValidString(): void + { + $html = ''; + (new Html())->loadFromString($html); + self::assertEmpty(libxml_get_errors()); + } +} diff --git a/tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php b/tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php index 91869dc6a0..5fa7ccf43f 100644 --- a/tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Html/HtmlLoadStringTest.php @@ -40,12 +40,14 @@ public function testCanLoadFromString(): void public function testLoadInvalidString(): void { - $this->expectException(ReaderException::class); - $html = ''; - $spreadsheet = (new Html())->loadFromString($html); - $firstSheet = $spreadsheet->getSheet(0); - $cellStyle = $firstSheet->getStyle('A1'); - self::assertFalse($cellStyle->getAlignment()->getWrapText()); + if (method_exists($this, 'setOutputCallback')) { + $this->expectException(ReaderException::class); + $html = ''; + (new Html())->loadFromString($html); + } else { + // The meat of this test runs in HtmlPhpunit10Test + self::assertTrue(true); + } } public function testCanLoadFromStringIntoExistingSpreadsheet(): void diff --git a/tests/PhpSpreadsheetTests/Reader/Html/HtmlPhpunit10Test.php b/tests/PhpSpreadsheetTests/Reader/Html/HtmlPhpunit10Test.php new file mode 100644 index 0000000000..fce30b121a --- /dev/null +++ b/tests/PhpSpreadsheetTests/Reader/Html/HtmlPhpunit10Test.php @@ -0,0 +1,57 @@ +canRead($filename)); + $reader->load($filename); + self::assertStringContainsString('DOMDocument::loadHTML', self::$errorString); + } + + public function testLoadInvalidString(): void + { + $html = ''; + (new Html())->loadFromString($html); + self::assertStringContainsString('DOMDocument::loadHTML', self::$errorString); + } +} diff --git a/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php b/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php index 38379b8ab1..5f80b2581b 100644 --- a/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Html/HtmlTest.php @@ -25,8 +25,12 @@ public function testBadHtml(): void $reader = new Html(); self::assertTrue($reader->canRead($filename)); - $this->expectException(ReaderException::class); - $reader->load($filename); + if (method_exists($this, 'setOutputCallback')) { + // The meat of this test is moved to HtmlPhpunit10Test + // to run under all PhpUnit versions. + $this->expectException(ReaderException::class); + $reader->load($filename); + } } public function testNonHtml(): void @@ -46,7 +50,7 @@ public function testInvalidFilename(): void self::assertFalse($reader->canRead('')); } - public function providerCanReadVerySmallFile(): array + public static function providerCanReadVerySmallFile(): array { $padding = str_repeat('a', 2048); diff --git a/tests/PhpSpreadsheetTests/Reader/Xml/XmlTest.php b/tests/PhpSpreadsheetTests/Reader/Xml/XmlTest.php index def2d63ec8..e2e1a9ce0c 100644 --- a/tests/PhpSpreadsheetTests/Reader/Xml/XmlTest.php +++ b/tests/PhpSpreadsheetTests/Reader/Xml/XmlTest.php @@ -13,13 +13,16 @@ class XmlTest extends TestCase */ public function testInvalidSimpleXML(string $filename): void { - $this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class); - $xmlReader = new Xml(); - $xmlReader->trySimpleXMLLoadString($filename); + if (method_exists($this, 'setOutputCallback')) { + $this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class); + self::assertFalse($xmlReader->trySimpleXMLLoadString($filename)); + } + + self::assertFalse(@$xmlReader->trySimpleXMLLoadString($filename)); } - public function providerInvalidSimpleXML(): array + public static function providerInvalidSimpleXML(): array { $tests = []; $glob = glob('tests/data/Reader/Xml/XEETestInvalidSimpleXML*.xml'); @@ -54,7 +57,8 @@ public function testLoadCorruptedFile(): void $this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class); $xmlReader = new Xml(); - $xmlReader->load('tests/data/Reader/Xml/CorruptedXmlFile.xml'); + $spreadsheet = /** @scrutinizer ignore-unhandled */ @$xmlReader->load('tests/data/Reader/Xml/CorruptedXmlFile.xml'); + self::assertNotSame('', $spreadsheet->getID()); } public function testListWorksheetNamesCorruptedFile(): void @@ -62,7 +66,8 @@ public function testListWorksheetNamesCorruptedFile(): void $this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class); $xmlReader = new Xml(); - $xmlReader->listWorksheetNames('tests/data/Reader/Xml/CorruptedXmlFile.xml'); + $names = /** @scrutinizer ignore-unhandled */ @$xmlReader->listWorksheetNames('tests/data/Reader/Xml/CorruptedXmlFile.xml'); + self::assertNotEmpty($names); } public function testListWorksheetInfoCorruptedFile(): void @@ -70,6 +75,7 @@ public function testListWorksheetInfoCorruptedFile(): void $this->expectException(\PhpOffice\PhpSpreadsheet\Reader\Exception::class); $xmlReader = new Xml(); - $xmlReader->listWorksheetInfo('tests/data/Reader/Xml/CorruptedXmlFile.xml'); + $info = /** @scrutinizer ignore-unhandled */ @$xmlReader->listWorksheetInfo('tests/data/Reader/Xml/CorruptedXmlFile.xml'); + self::assertNotEmpty($info); } } diff --git a/tests/PhpSpreadsheetTests/Shared/OLEPhpunit10Test.php b/tests/PhpSpreadsheetTests/Shared/OLEPhpunit10Test.php new file mode 100644 index 0000000000..2bf88b3ff3 --- /dev/null +++ b/tests/PhpSpreadsheetTests/Shared/OLEPhpunit10Test.php @@ -0,0 +1,63 @@ +stream_open('whatever', 'w', 0, $openedPath)); + + $ole->stream_open('whatever', 'w', STREAM_REPORT_ERRORS, $openedPath); + self::assertSame('Only reading is supported', self::$errorString); + } + + public function testChainedBadPath(): void + { + self::assertSame('', self::$errorString); + $ole = new OLE\ChainedBlockStream(); + $openedPath = ''; + self::assertFalse($ole->stream_open('whatever', 'r', 0, $openedPath)); + + $ole->stream_open('whatever', 'r', STREAM_REPORT_ERRORS, $openedPath); + self::assertSame('OLE stream not found', self::$errorString); + } +} diff --git a/tests/PhpSpreadsheetTests/Shared/OLETest.php b/tests/PhpSpreadsheetTests/Shared/OLETest.php index bef137f27c..db81272c55 100644 --- a/tests/PhpSpreadsheetTests/Shared/OLETest.php +++ b/tests/PhpSpreadsheetTests/Shared/OLETest.php @@ -46,11 +46,14 @@ public function testChainedWriteMode(): void $openedPath = ''; self::assertFalse($ole->stream_open('whatever', 'w', 0, $openedPath)); - try { - $ole->stream_open('whatever', 'w', STREAM_REPORT_ERRORS, $openedPath); - self::fail('Error in statement above should be caught'); - } catch (Throwable $e) { - self::assertSame('Only reading is supported', $e->getMessage()); + // Test moved to OLEPhpunit10Test for PhpUnit 10 + if (method_exists($this, 'setOutputCallback')) { + try { + $ole->stream_open('whatever', 'w', STREAM_REPORT_ERRORS, $openedPath); + self::fail('Error in statement above should be caught'); + } catch (Throwable $e) { + self::assertSame('Only reading is supported', $e->getMessage()); + } } } @@ -60,11 +63,14 @@ public function testChainedBadPath(): void $openedPath = ''; self::assertFalse($ole->stream_open('whatever', 'r', 0, $openedPath)); - try { - $ole->stream_open('whatever', 'r', STREAM_REPORT_ERRORS, $openedPath); - self::fail('Error in statement above should be caught'); - } catch (Throwable $e) { - self::assertSame('OLE stream not found', $e->getMessage()); + // Not sure how to do this test with PhpUnit 10 + if (method_exists($this, 'setOutputCallback')) { + try { + $ole->stream_open('whatever', 'r', STREAM_REPORT_ERRORS, $openedPath); + self::fail('Error in statement above should be caught'); + } catch (Throwable $e) { + self::assertSame('OLE stream not found', $e->getMessage()); + } } } } diff --git a/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorEmptyTest.php b/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorEmptyTest.php index 70cc39ec13..47c403729b 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorEmptyTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorEmptyTest.php @@ -45,7 +45,7 @@ public function testIteratorEmptyColumn(string $columnId, bool $expectedEmpty): $spreadsheet->disconnectWorksheets(); } - public function emptyColumnBasic(): array + public static function emptyColumnBasic(): array { return [ ['A', false], @@ -75,7 +75,7 @@ public function testIteratorEmptyColumnWithNull(string $columnId, bool $expected $spreadsheet->disconnectWorksheets(); } - public function emptyColumnNullAsEmpty(): array + public static function emptyColumnNullAsEmpty(): array { return [ ['A', false], @@ -105,7 +105,7 @@ public function testIteratorEmptyColumnWithEmptyString(string $columnId, bool $e $spreadsheet->disconnectWorksheets(); } - public function emptyColumnEmptyStringAsEmpty(): array + public static function emptyColumnEmptyStringAsEmpty(): array { return [ ['A', false], @@ -137,7 +137,7 @@ public function testIteratorEmptyColumnWithNullAndEmptyString(string $columnId, $spreadsheet->disconnectWorksheets(); } - public function emptyColumnNullAndEmptyStringAsEmpty(): array + public static function emptyColumnNullAndEmptyStringAsEmpty(): array { return [ ['A', false], diff --git a/tests/PhpSpreadsheetTests/Worksheet/MergeBehaviourTest.php b/tests/PhpSpreadsheetTests/Worksheet/MergeBehaviourTest.php index 7d7a2c8366..ab79ad8302 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/MergeBehaviourTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/MergeBehaviourTest.php @@ -11,7 +11,7 @@ class MergeBehaviourTest extends AbstractFunctional /** * @var array */ - private $testDataRaw = [ + private static $testDataRaw = [ [1.1, 2.2, '=ROUND(A1+B1, 1)'], [4.4, 5.5, '=ROUND(A2+B2, 1)'], ['=ROUND(A1+A2, 1)', '=ROUND(B1+B2, 1)', '=ROUND(A3+B3, 1)'], @@ -35,7 +35,7 @@ public function testMergeCellsDefaultBehaviour(): void $mergeRange = 'A1:C3'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); - $worksheet->fromArray($this->testDataRaw, null, 'A1', true); + $worksheet->fromArray(self::$testDataRaw, null, 'A1', true); $worksheet->mergeCells($mergeRange); $mergeResult = $worksheet->toArray(null, true, false, false); @@ -72,7 +72,7 @@ public function testMergeCellsHideBehaviour(): void $mergeRange = 'A1:C3'; $spreadsheet = new Spreadsheet(); $worksheet = $spreadsheet->getActiveSheet(); - $worksheet->fromArray($this->testDataRaw, null, 'A1', true); + $worksheet->fromArray(self::$testDataRaw, null, 'A1', true); $worksheet->mergeCells($mergeRange, Worksheet::MERGE_CELL_CONTENT_HIDE); $mergeResult = $worksheet->toArray(null, true, false, false); @@ -115,11 +115,11 @@ public function testMergeCellsMergeBehaviour(array $testData, string $mergeRange $spreadsheet->disconnectWorksheets(); } - public function mergeCellsMergeBehaviourProvider(): array + public static function mergeCellsMergeBehaviourProvider(): array { return [ 'With Calculated Values' => [ - $this->testDataRaw, + self::$testDataRaw, 'A1:C3', [ ['1.1 2.2 1.1 4.4 5.5 0 1.1 0 0', null, null], diff --git a/tests/PhpSpreadsheetTests/Worksheet/RowIteratorEmptyTest.php b/tests/PhpSpreadsheetTests/Worksheet/RowIteratorEmptyTest.php index c971f6dfe8..ec062a032f 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/RowIteratorEmptyTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/RowIteratorEmptyTest.php @@ -47,7 +47,7 @@ public function testIteratorEmptyRow(int $rowId, bool $expectedEmpty): void $spreadsheet->disconnectWorksheets(); } - public function emptyRowBasic(): array + public static function emptyRowBasic(): array { return [ [1, false], @@ -77,7 +77,7 @@ public function testIteratorEmptyRowWithNull(int $rowId, bool $expectedEmpty): v $spreadsheet->disconnectWorksheets(); } - public function emptyRowNullAsEmpty(): array + public static function emptyRowNullAsEmpty(): array { return [ [1, false], @@ -107,7 +107,7 @@ public function testIteratorEmptyRowWithEmptyString(int $rowId, bool $expectedEm $spreadsheet->disconnectWorksheets(); } - public function emptyRowEmptyStringAsEmpty(): array + public static function emptyRowEmptyStringAsEmpty(): array { return [ [1, false], @@ -139,7 +139,7 @@ public function testIteratorEmptyRowWithNullAndEmptyString(int $rowId, bool $exp $spreadsheet->disconnectWorksheets(); } - public function emptyRowNullAndEmptyStringAsEmpty(): array + public static function emptyRowNullAndEmptyStringAsEmpty(): array { return [ [1, false], diff --git a/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php b/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php index 26e537ba42..8c7a4e8eae 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/Table/TableTest.php @@ -36,7 +36,7 @@ public function testValidTableNames(string $name, string $expected): void self::assertEquals($expected, $table->getName()); } - public function validTableNamesProvider(): array + public static function validTableNamesProvider(): array { return [ ['', ''], @@ -61,7 +61,7 @@ public function testInvalidTableNames(string $name): void $table->setName($name); } - public function invalidTableNamesProvider(): array + public static function invalidTableNamesProvider(): array { return [ ['C'], @@ -152,12 +152,10 @@ public function testGetRange(): void } /** - * @dataProvider validTableRangeProvider - * * @param AddressRange|array|string $fullRange * @param string $fullRange */ - public function testSetRangeValidRange($fullRange, string $actualRange): void + public function xtestSetRangeValidRange($fullRange, string $actualRange): void { $table = new Table(self::INITIAL_RANGE); @@ -166,7 +164,14 @@ public function testSetRangeValidRange($fullRange, string $actualRange): void self::assertEquals($actualRange, $table->getRange()); } - public function validTableRangeProvider(): array + public function testSetRangeValidRange(): void + { + foreach ($this->validTableRanges() as $arrayEntry) { + $this->xtestSetRangeValidRange($arrayEntry[0], $arrayEntry[1]); + } + } + + public function validTableRanges(): array { $sheet = $this->getSheet(); $title = $sheet->getTitle(); @@ -203,7 +208,7 @@ public function testSetRangeInvalidRange(string $range): void new Table($range); } - public function invalidTableRangeProvider(): array + public static function invalidTableRangeProvider(): array { return [ ['A1'], diff --git a/tests/PhpSpreadsheetTests/Writer/Xls/WorkbookTest.php b/tests/PhpSpreadsheetTests/Writer/Xls/WorkbookTest.php index 160a665ad3..ed3deb3e6a 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xls/WorkbookTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Xls/WorkbookTest.php @@ -15,9 +15,23 @@ class WorkbookTest extends TestCase */ private $workbook; - protected function setUp(): void + /** @var ?Spreadsheet */ + private $spreadsheet; + + protected function tearDown(): void + { + if ($this->spreadsheet !== null) { + $this->spreadsheet->disconnectWorksheets(); + $this->spreadsheet = null; + } + } + + private function setUpWorkbook(): void { - $spreadsheet = new Spreadsheet(); + if ($this->spreadsheet !== null) { + $this->spreadsheet->disconnectWorksheets(); + } + $this->spreadsheet = $spreadsheet = new Spreadsheet(); $strTotal = 0; $strUnique = 0; $str_table = []; @@ -27,10 +41,7 @@ protected function setUp(): void $this->workbook = new Workbook($spreadsheet, $strTotal, $strUnique, $str_table, $colors, $parser); } - /** - * @dataProvider providerAddColor - */ - public function testAddColor(array $testColors, array $expectedResult): void + public function xtestAddColor(array $testColors, array $expectedResult): void { $workbookReflection = new ReflectionClass(Workbook::class); $methodAddColor = $workbookReflection->getMethod('addColor'); @@ -47,9 +58,20 @@ public function testAddColor(array $testColors, array $expectedResult): void self::assertEquals($expectedResult, $palette); } - public function providerAddColor(): array + public function testAddColor(): void + { + $i = 0; + $arrayEntries = $this->arrayAddColor(); + while ($i < count($arrayEntries)) { + $this->xtestAddColor($arrayEntries[$i][0], $arrayEntries[$i][1]); + ++$i; + $arrayEntries = $this->arrayAddColor(); + } + } + + public function arrayAddColor(): array { - $this->setUp(); + $this->setUpWorkbook(); $workbookReflection = new ReflectionClass(Workbook::class); $propertyPalette = $workbookReflection->getProperty('palette');