Skip to content

Commit

Permalink
PhpUnit 10 Compatibility Part 2 (PHPOffice#3526)
Browse files Browse the repository at this point in the history
Successor to PR PHPOffice#3523. There are 494 single-line changes (`public function provider` to `public static function provider`) in this PR. None of these were made manually; they were all created with the following script (adapted from
https://stackoverflow.com/questions/25909820/how-to-recursively-iterate-through-files-in-php):
```php
$dir = 'C:/git/unit10prep2/tests/PhpSpreadsheetTests';
$it = new RecursiveDirectoryIterator($dir);

// Loop through files
foreach(new RecursiveIteratorIterator($it) as $file) {
    if ($file->getExtension() === 'php') {
        $contents = file_get_contents($file);
        $new = preg_replace('/public function (\\w*)([Pp])rovider/', 'public static function $1$2rovider', $contents);
        if ($new !== $contents) {
            echo "changing $file\n";
            file_put_contents($file, $new);
        }
    }
}
```

After this PR, there will be one more, with a small number of test changes, and enabling PhpUnit 10 for Php 8.1+.
  • Loading branch information
oleibman authored Apr 20, 2023
1 parent 1187825 commit e9cf273
Show file tree
Hide file tree
Showing 494 changed files with 994 additions and 994 deletions.
2 changes: 1 addition & 1 deletion tests/PhpSpreadsheetTests/Calculation/ArrayFormulaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testArrayFormula(string $formula, $expectedResult): void
self::assertEquals($expectedResult, $result);
}

public function providerArrayFormulae(): array
public static function providerArrayFormulae(): array
{
return [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testBinaryComparisonOperation(
self::assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible');
}

public function providerBinaryComparison(): array
public static function providerBinaryComparison(): array
{
return require 'tests/data/Calculation/BinaryComparisonOperations.php';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testGetFunctions(/** @scrutinizer ignore-unused */ $category, $f
self::assertIsCallable($functionCall);
}

public function providerGetFunctions(): array
public static function providerGetFunctions(): array
{
return Calculation::getInstance()->getFunctions();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testInvalidLocaleReturnsFalse(): void
self::assertFalse($calculation->setLocale('xx'));
}

public function providerCanLoadAllSupportedLocales(): array
public static function providerCanLoadAllSupportedLocales(): array
{
return [
['bg'],
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpSpreadsheetTests/Calculation/CalculationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testBinaryComparisonOperation($formula, $expectedResultExcel, $e
self::assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible');
}

public function providerBinaryComparisonOperation(): array
public static function providerBinaryComparisonOperation(): array
{
return require 'tests/data/CalculationBinaryComparisonOperation.php';
}
Expand Down Expand Up @@ -406,7 +406,7 @@ public function testFullExecutionDataPruning(
self::assertEquals($expectedResult, $calculated);
}

public function dataProviderBranchPruningFullExecution(): array
public static function dataProviderBranchPruningFullExecution(): array
{
return require 'tests/data/Calculation/Calculation.php';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testNumber($expected, string $value): void
self::assertSame($expected, $value);
}

public function providerNumbers(): array
public static function providerNumbers(): array
{
return [
[-12.5, '-12.5'],
Expand Down Expand Up @@ -47,7 +47,7 @@ public function testFraction(string $expected, string $value): void
}
}

public function providerFractions(): array
public static function providerFractions(): array
{
return [
'non-fraction' => ['1', '1'],
Expand Down Expand Up @@ -76,7 +76,7 @@ public function testPercentage(string $expected, string $value): void
}
}

public function providerPercentages(): array
public static function providerPercentages(): array
{
return [
'non-percentage' => ['10', '10'],
Expand Down Expand Up @@ -205,7 +205,7 @@ public function testCurrencies(string $expected, string $value): void
}
}

public function providerCurrencies(): array
public static function providerCurrencies(): array
{
$currencyCode = StringHelper::getCurrencyCode();

Expand Down
8 changes: 4 additions & 4 deletions tests/PhpSpreadsheetTests/Calculation/Engine/RangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testRangeEvaluation(string $formula, $expectedResult): void
self::assertSame($expectedResult, $actualRresult);
}

public function providerRangeEvaluation(): array
public static function providerRangeEvaluation(): array
{
return[
'Sum with Simple Range' => ['=SUM(A1:C3)', 72],
Expand Down Expand Up @@ -93,7 +93,7 @@ public function testNamedRangeEvaluation(array $ranges, string $formula, int $ex
self::assertSame($expectedResult, $sumRresult);
}

public function providerNamedRangeEvaluation(): array
public static function providerNamedRangeEvaluation(): array
{
return[
[['$A$1:$B$3', '$A$1:$C$2'], '=SUM(GROUP1,GROUP2)', 75],
Expand Down Expand Up @@ -131,7 +131,7 @@ public function testUTF8NamedRangeEvaluation(array $names, array $ranges, string
self::assertSame($expectedResult, $sumRresult);
}

public function providerUTF8NamedRangeEvaluation(): array
public static function providerUTF8NamedRangeEvaluation(): array
{
return[
[['Γειά', 'σου', 'Κόσμε'], ['$A$1', '$B$1:$B$2', '$C$1:$C$3'], '=SUM(Γειά,σου,Κόσμε)', 38],
Expand Down Expand Up @@ -161,7 +161,7 @@ public function testCompositeNamedRangeEvaluation(string $composite, int $expect
self::assertSame($expectedCount, $actualCount);
}

public function providerCompositeNamedRangeEvaluation(): array
public static function providerCompositeNamedRangeEvaluation(): array
{
return[
// Calculation engine doesn't yet handle union ranges with overlap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testStructuredReferenceHeadersHidden(): void
$structuredReferenceObject->parse($cell);
}

public function structuredReferenceProviderColumnData(): array
public static function structuredReferenceProviderColumnData(): array
{
return [
// Full table, with no column specified, means data only, not headers or totals
Expand Down Expand Up @@ -151,7 +151,7 @@ public function structuredReferenceProviderColumnData(): array
];
}

public function structuredReferenceProviderRowData(): array
public static function structuredReferenceProviderRowData(): array
{
return [
['E5', 'DeptSales[[#This Row], [Commission Amount]]'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testFunctionsAsString($expectedResult, $formula): void
self::assertEquals($expectedResult, $result);
}

public function providerFunctionsAsString(): array
public static function providerFunctionsAsString(): array
{
return require 'tests/data/Calculation/FunctionsAsString.php';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testFormulaParser(string $formula, array $expectedResult): void
}
}

public function providerFormulaParser(): array
public static function providerFormulaParser(): array
{
return [
['5%*(2+(-3))+A3',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testDATEDIFInWorksheet($expectedResult, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerDATEDIF(): array
public static function providerDATEDIF(): array
{
return require 'tests/data/Calculation/DateTime/DATEDIF.php';
}
Expand All @@ -91,7 +91,7 @@ public function testDATEDIFUnhappyPath(string $expectedException, ...$args): voi
$spreadsheet->disconnectWorksheets();
}

public function providerUnhappyDATEDIF(): array
public static function providerUnhappyDATEDIF(): array
{
return [
['Formula Error: Wrong number of arguments for DATEDIF() function', '2023-03-1'],
Expand Down Expand Up @@ -128,7 +128,7 @@ public function testDateDifArray(array $expectedResult, string $startDate, strin
self::assertSame($expectedResult, $result);
}

public function providerDateDifArray(): array
public static function providerDateDifArray(): array
{
return [
'row vector #1' => [[[364, 202, '#NUM!']], '{"2022-01-01", "2022-06-12", "2023-07-22"}', '"2022-12-31"', null],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function testDATEInWorksheet($expectedResult, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerDATE(): array
public static function providerDATE(): array
{
return require 'tests/data/Calculation/DateTime/DATE.php';
}
Expand All @@ -115,7 +115,7 @@ public function testDATEUnhappyPath(string $expectedException, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerUnhappyDATE(): array
public static function providerUnhappyDATE(): array
{
return [
['Formula Error: Wrong number of arguments for DATE() function', 2023, 03],
Expand Down Expand Up @@ -166,7 +166,7 @@ public function testDateArray(array $expectedResult, string $year, string $month
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}

public function providerDateArray(): array
public static function providerDateArray(): array
{
return [
'row vector year' => [[[44197, 44562, 44927]], '{2021,2022,2023}', '1', '1'],
Expand Down Expand Up @@ -234,7 +234,7 @@ public function testDateArrayException(string $year, string $month, string $day)
$calculation->_calculateFormulaValue($formula);
}

public function providerDateArrayException(): array
public static function providerDateArrayException(): array
{
return [
'matrix arguments with 3 array values' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function testDATEVALUEInWorksheet($expectedResult, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerDATEVALUE(): array
public static function providerDATEVALUE(): array
{
return require 'tests/data/Calculation/DateTime/DATEVALUE.php';
}
Expand All @@ -143,7 +143,7 @@ public function testDATEVALUEUnhappyPath(string $expectedException, ...$args): v
$spreadsheet->disconnectWorksheets();
}

public function providerUnhappyDATEVALUE(): array
public static function providerUnhappyDATEVALUE(): array
{
return [
['Formula Error: Wrong number of arguments for DATEVALUE() function'],
Expand Down Expand Up @@ -194,7 +194,7 @@ public function testDateValueArray(array $expectedResult, string $array): void
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}

public function providerDateValueArray(): array
public static function providerDateValueArray(): array
{
return [
'row vector' => [[[44562, 44724, 45129]], '{"2022-01-01", "2022-06-12", "2023-07-22"}'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testDAYInWorksheet($expectedResult, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerDAY(): array
public static function providerDAY(): array
{
return require 'tests/data/Calculation/DateTime/DAY.php';
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public function testDAYAsFormulaOpenOffice($expectedResultOpenOffice, ...$args):
self::assertSame($expectedResultOpenOffice, $result);
}

public function providerDAYOpenOffice(): array
public static function providerDAYOpenOffice(): array
{
return require 'tests/data/Calculation/DateTime/DAYOpenOffice.php';
}
Expand All @@ -144,7 +144,7 @@ public function testDAYUnhappyPath(string $expectedException, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerUnhappyDAY(): array
public static function providerUnhappyDAY(): array
{
return [
['Formula Error: Wrong number of arguments for DAY() function'],
Expand All @@ -169,7 +169,7 @@ public function testDayArray(array $expectedResult, string $array): void
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}

public function providerDayArray(): array
public static function providerDayArray(): array
{
return [
'row vector' => [[[1, 12, 22]], '{"2022-01-01", "2022-06-12", "2023-07-22"}'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testDAYS360InWorksheet($expectedResult, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerDAYS360(): array
public static function providerDAYS360(): array
{
return require 'tests/data/Calculation/DateTime/DAYS360.php';
}
Expand All @@ -92,7 +92,7 @@ public function testDAYS360UnhappyPath(string $expectedException, ...$args): voi
$spreadsheet->disconnectWorksheets();
}

public function providerUnhappyDAYS360(): array
public static function providerUnhappyDAYS360(): array
{
return [
['Formula Error: Wrong number of arguments for DAYS360() function'],
Expand Down Expand Up @@ -129,7 +129,7 @@ public function testDays360Array(array $expectedResult, string $startDate, strin
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}

public function providerDays360Array(): array
public static function providerDays360Array(): array
{
return [
'row vector #1' => [[[360, 199, -201]], '{"2022-01-01", "2022-06-12", "2023-07-22"}', '"2022-12-31"', null],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function testDAYSInWorksheet($expectedResult, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerDAYS(): array
public static function providerDAYS(): array
{
return require 'tests/data/Calculation/DateTime/DAYS.php';
}
Expand All @@ -90,7 +90,7 @@ public function testDAYSUnhappyPath(string $expectedException, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerUnhappyDAYS(): array
public static function providerUnhappyDAYS(): array
{
return [
['Formula Error: Wrong number of arguments for DAYS() function', '2023-04-01'],
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testDaysArray(array $expectedResult, string $startDate, string $
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}

public function providerDaysArray(): array
public static function providerDaysArray(): array
{
return [
'row vector #1' => [[[-364, -202, 203]], '{"2022-01-01", "2022-06-12", "2023-07-22"}', '"2022-12-31"'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testEDATEInWorksheet($expectedResult, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerEDATE(): array
public static function providerEDATE(): array
{
return require 'tests/data/Calculation/DateTime/EDATE.php';
}
Expand All @@ -106,7 +106,7 @@ public function testEDATEUnhappyPath(string $expectedException, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerUnhappyEDATE(): array
public static function providerUnhappyEDATE(): array
{
return [
['Formula Error: Wrong number of arguments for EDATE() function', null],
Expand Down Expand Up @@ -148,7 +148,7 @@ public function testEDateArray(array $expectedResult, string $dateValues, string
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}

public function providerEDateArray(): array
public static function providerEDateArray(): array
{
return [
'row vector #1' => [[[44593, 44632, 45337]], '{"2022-01-01", "2022-02-12", "2024-01-15"}', '1'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testEOMONTHInWorksheet($expectedResult, ...$args): void
$spreadsheet->disconnectWorksheets();
}

public function providerEOMONTH(): array
public static function providerEOMONTH(): array
{
return require 'tests/data/Calculation/DateTime/EOMONTH.php';
}
Expand All @@ -106,7 +106,7 @@ public function testEOMONTHUnhappyPath(string $expectedException, ...$args): voi
$spreadsheet->disconnectWorksheets();
}

public function providerUnhappyEOMONTH(): array
public static function providerUnhappyEOMONTH(): array
{
return [
['Formula Error: Wrong number of arguments for EOMONTH() function'],
Expand Down Expand Up @@ -147,7 +147,7 @@ public function testEoMonthArray(array $expectedResult, string $dateValues, stri
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}

public function providerEoMonthArray(): array
public static function providerEoMonthArray(): array
{
return [
'row vector #1' => [[[44620, 44651, 45351]], '{"2022-01-01", "2022-02-12", "2024-01-15"}', '1'],
Expand Down
Loading

0 comments on commit e9cf273

Please sign in to comment.