From 1187825738b50568c66b1132e74c95efd64a2982 Mon Sep 17 00:00:00 2001
From: oleibman <10341515+oleibman@users.noreply.github.com>
Date: Tue, 18 Apr 2023 19:50:59 -0700
Subject: [PATCH] PhpUnit 10 Compatibility Part 1 (#3523)
* PhpUnit 10 Compatibility Part 1
This is not a change to move to PhpUnit 10. There is no compelling reason to do so at this time, although it is bound to happen eventually. There are a staggering number of problems (somewhere around 3,000) with the current test suite under PhpUnit 10; this is an attempt to get ahead of the curve by addressing them now.
Method `setOutputCallback` has gone away. This affects only Helper/SampleTest. It appears that `ob_start` and its allies provide an effective equivalent. FWIW, the absence of `setOutputCallback` is a good indication of whether or not PhpUnit 10 is in use, and I will use that fact in a few tests.
Class `ComplexAssert` with no constructor, and always used with `new ComplexAssert()`, extends `TestCase`. Apparently, the constructor for TestCase requires an argument, and PhpUnit 10 complains about not supplying one. Adding an empty constructor to ComplexAssert avoids this problem.
There are two very minor source changes, to Calculation/Calculation and Reader/Xlsx, where problems were exposed with PhpUnit 10 that had not been previously been exposed. AFAIK, these are the only source changes required; the rest of the changes are to test members.
The bulk of the problems are because PhpUnit 10 insists that provider methods be static. Most of those can be changed by a script without any further action; those changes will constitute the Part 2 counterpart of this PR. In this PR you will find the exceptional cases that can't be automated for one reason or another. The tests for Database functions have mild complications that are easily handled. Most of the other provider changes in this PR are because the method names didn't follow an established pattern ('provider' isn't part of the method name); those are also easily handled manually. Modifying the following tests provided significant challenges:
- Writer/Xls/WorkbookTest testAddColor
- Worksheet/Table/TableTest testSetRangeValidRange
The handling of warning messages issued by the code differs in PhpUnit 10. According to the change log, "This means that using PHP functionality which triggers E_DEPRECATED, E_NOTICE, E_STRICT, or E_WARNING or calling code which triggers E_USER_DEPRECATED, E_USER_NOTICE, or E_USER_WARNING can no longer hide a bug in your code." To me, the effect of that change seems to be exactly the opposite - such messages were available to the test with PhpUnit 9 (so we could test for them), and are no longer available (so we can't). I haven't even succeeded with a custom error message handler as part of the script. I will continue to investigate, but, for now, will skip some tests under PhpUnit 10 for the following:
- Shared/OleTest testChainedWriteMode and testChainedBadPath
- Reader/Html/HtmlLoadStringTest testLoadInvalidString
- Reader/Html/HtmlTest testBadHtml
* Scrutinize, and Parent Construct
Parent construct suggested by @MarkBaker.
* Redo Tests Dependent on Warning Messages
Warning (and other) messages are handled differently in PhpUnit 10 than in earlier versions.
---
.../Calculation/Calculation.php | 2 +-
src/PhpSpreadsheet/Reader/Xlsx.php | 2 +-
.../DefinedNamesCalculationTest.php | 4 +-
.../Functions/Database/DAverageTest.php | 32 +++++-----
.../Functions/Database/DCountATest.php | 12 ++--
.../Functions/Database/DCountTest.php | 28 ++++-----
.../Functions/Database/DGetTest.php | 14 ++---
.../Functions/Database/DMaxTest.php | 24 +++----
.../Functions/Database/DMinTest.php | 24 +++----
.../Functions/Database/DProductTest.php | 14 ++---
.../Functions/Database/DStDevPTest.php | 16 ++---
.../Functions/Database/DStDevTest.php | 12 ++--
.../Functions/Database/DSumTest.php | 16 ++---
.../Functions/Database/DVarPTest.php | 12 ++--
.../Functions/Database/DVarTest.php | 12 ++--
.../Database/SetupTeardownDatabases.php | 8 +--
.../Functions/LookupRef/SortByTest.php | 32 +++++-----
.../Functions/LookupRef/SortTest.php | 28 ++++-----
tests/PhpSpreadsheetTests/Cell/CellTest.php | 2 +-
.../Custom/ComplexAssert.php | 5 ++
.../PhpSpreadsheetTests/Helper/SampleTest.php | 8 +--
.../Reader/Html/HtmlLibxmlTest.php | 46 ++++++++++++++
.../Reader/Html/HtmlLoadStringTest.php | 14 +++--
.../Reader/Html/HtmlPhpunit10Test.php | 57 +++++++++++++++++
.../Reader/Html/HtmlTest.php | 10 ++-
.../Reader/Xml/XmlTest.php | 20 +++---
.../Shared/OLEPhpunit10Test.php | 63 +++++++++++++++++++
tests/PhpSpreadsheetTests/Shared/OLETest.php | 26 +++++---
.../Worksheet/ColumnIteratorEmptyTest.php | 8 +--
.../Worksheet/MergeBehaviourTest.php | 10 +--
.../Worksheet/RowIteratorEmptyTest.php | 8 +--
.../Worksheet/Table/TableTest.php | 19 +++---
.../Writer/Xls/WorkbookTest.php | 38 ++++++++---
33 files changed, 420 insertions(+), 206 deletions(-)
create mode 100644 tests/PhpSpreadsheetTests/Reader/Html/HtmlLibxmlTest.php
create mode 100644 tests/PhpSpreadsheetTests/Reader/Html/HtmlPhpunit10Test.php
create mode 100644 tests/PhpSpreadsheetTests/Shared/OLEPhpunit10Test.php
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 = '