Skip to content

Commit

Permalink
Merge pull request #4239 from oleibman/phpunit11d
Browse files Browse the repository at this point in the history
Use Php Attributes Rather than Annotations for PhpUnit
  • Loading branch information
oleibman authored Nov 26, 2024
2 parents fd562af + d647fe7 commit a70b335
Show file tree
Hide file tree
Showing 549 changed files with 1,263 additions and 3,742 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
'ordered_imports' => true,
'ordered_interfaces' => true,
'ordered_traits' => true,
'php_unit_attributes' => ['keep_annotations' => false],
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'php_unit_dedicate_assert_internal_type' => true,
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This makes it easier to see exactly what is being tested when reviewing the PR.
2. Tag subject must be the version number, eg: `1.2.3`
3. Tag body must be a copy-paste of the changelog entries.
3. Push the tag with `git push --tags`, GitHub Actions will create a GitHub release automatically, and the release details will automatically be sent to packagist.
4. By default, Github remove markdown headings in the Release Notes. You can either edit to restore these, or, probably preferably, change the default comment character on your system - `git config core.commentChar ';'`.
4. By default, Github removes markdown headings in the Release Notes. You can either edit to restore these, or, probably preferably, change the default comment character on your system - `git config core.commentChar ";"`.

> **Note:** Tagged releases are made from the `master` branch. Only in an emergency should a tagged release be made from the `release` branch. (i.e. cherry-picked hot-fixes.) However, there are 3 branches which have been updated to apply security patches, and those may be tagged if future security updates are needed.
- release1291
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"phpcompatibility/php-compatibility": "^9.3",
"phpstan/phpstan": "^1.1",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.6 || ^10.5",
"phpunit/phpunit": "^10.5",
"squizlabs/php_codesniffer": "^3.7",
"tecnickcom/tcpdf": "^6.5"
},
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<coverage/>
<php>
<ini name="memory_limit" value="2048M"/>
<ini name="error_reporting" value="E_ALL"/>
</php>
<testsuite name="PhpSpreadsheet Unit Test Suite">
<directory>./tests/PhpSpreadsheetTests</directory>
Expand Down
15 changes: 0 additions & 15 deletions phpunit9.xml.dist

This file was deleted.

4 changes: 1 addition & 3 deletions tests/PhpSpreadsheetTests/Calculation/ArrayFormulaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

class ArrayFormulaTest extends TestCase
{
/**
* @dataProvider providerArrayFormulae
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerArrayFormulae')]
public function testArrayFormula(string $formula, mixed $expectedResult): void
{
$result = Calculation::getInstance()->_calculateFormulaValue($formula);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ protected function tearDown(): void
Functions::setCompatibilityMode($this->compatibilityMode);
}

/**
* @dataProvider providerBinaryComparison
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerBinaryComparison')]
public function testBinaryComparisonOperation(
mixed $operand1,
mixed $operand2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ protected function tearDown(): void
Functions::setCompatibilityMode($this->compatibilityMode);
}

/**
* @dataProvider providerGetFunctions
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerGetFunctions')]
public function testGetFunctions(array|string $functionCall): void
{
self::assertIsCallable($functionCall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ protected function tearDown(): void
$calculation->setLocale($this->locale);
}

/**
* @dataProvider providerCanLoadAllSupportedLocales
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerCanLoadAllSupportedLocales')]
public function testCanLoadAllSupportedLocales(string $locale): void
{
$calculation = Calculation::getInstance();
Expand Down
7 changes: 2 additions & 5 deletions tests/PhpSpreadsheetTests/Calculation/CalculationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ protected function tearDown(): void
Functions::setCompatibilityMode($this->compatibilityMode);
}

/**
* @dataProvider providerBinaryComparisonOperation
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerBinaryComparisonOperation')]
public function testBinaryComparisonOperation(string $formula, mixed $expectedResultExcel, mixed $expectedResultOpenOffice): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Expand Down Expand Up @@ -374,9 +372,8 @@ public function testBranchPruningFormulaParsingInequalitiesConditionsCase(): voi
* be set in cache
* @param string[] $shouldNotBeSetInCacheCells coordinates of cells that must
* not be set in cache because of pruning
*
* @dataProvider dataProviderBranchPruningFullExecution
*/
#[\PHPUnit\Framework\Attributes\DataProvider('dataProviderBranchPruningFullExecution')]
public function testFullExecutionDataPruning(
mixed $expectedResult,
array $dataArray,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

class DefinedNamesCalculationTest extends TestCase
{
/**
* @dataProvider namedRangeCalculationTest1
*/
#[\PHPUnit\Framework\Attributes\DataProvider('namedRangeCalculationTest1')]
public function testNamedRangeCalculations1(string $cellAddress, float $expectedValue): void
{
$inputFileType = 'Xlsx';
Expand All @@ -24,9 +22,7 @@ public function testNamedRangeCalculations1(string $cellAddress, float $expected
self::assertSame($expectedValue, $calculatedCellValue, "Failed calculation for cell {$cellAddress}");
}

/**
* @dataProvider namedRangeCalculationTest2
*/
#[\PHPUnit\Framework\Attributes\DataProvider('namedRangeCalculationTest2')]
public function testNamedRangeCalculationsWithAdjustedRateValue(string $cellAddress, float $expectedValue): void
{
$inputFileType = 'Xlsx';
Expand All @@ -41,9 +37,7 @@ public function testNamedRangeCalculationsWithAdjustedRateValue(string $cellAddr
self::assertSame($expectedValue, $calculatedCellValue, "Failed calculation for cell {$cellAddress}");
}

/**
* @dataProvider namedRangeCalculationTest1
*/
#[\PHPUnit\Framework\Attributes\DataProvider('namedRangeCalculationTest1')]
public function testNamedFormulaCalculations1(string $cellAddress, float $expectedValue): void
{
$inputFileType = 'Xlsx';
Expand All @@ -56,9 +50,7 @@ public function testNamedFormulaCalculations1(string $cellAddress, float $expect
self::assertSame($expectedValue, $calculatedCellValue, "Failed calculation for cell {$cellAddress}");
}

/**
* @dataProvider namedRangeCalculationTest2
*/
#[\PHPUnit\Framework\Attributes\DataProvider('namedRangeCalculationTest2')]
public function testNamedFormulaeCalculationsWithAdjustedRateValue(string $cellAddress, float $expectedValue): void
{
$inputFileType = 'Xlsx';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ protected function tearDown(): void
StringHelper::setThousandsSeparator(null);
}

/**
* @dataProvider providerNumbers
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerNumbers')]
public function testNumber(float $expected, string $value, string $thousandsSeparator = ',', string $decimalSeparator = '.'): void
{
StringHelper::setThousandsSeparator($thousandsSeparator);
Expand All @@ -38,9 +36,7 @@ public static function providerNumbers(): array
];
}

/**
* @dataProvider providerPercentages
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerPercentages')]
public function testPercentage(string $expected, string $value, string $thousandsSeparator = ',', string $decimalSeparator = '.'): void
{
$originalValue = $value;
Expand All @@ -61,9 +57,7 @@ public static function providerPercentages(): array
];
}

/**
* @dataProvider providerCurrencies
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerCurrencies')]
public function testCurrencies(string $expected, string $value, string $thousandsSeparator = ',', string $decimalSeparator = '.', ?string $currencyCode = null): void
{
$originalValue = $value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

class FormattedNumberTest extends TestCase
{
/**
* @dataProvider providerNumbers
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerNumbers')]
public function testNumber(float $expected, string $value): void
{
FormattedNumber::convertToNumberIfFormatted($value);
Expand All @@ -31,9 +29,7 @@ public static function providerNumbers(): array
];
}

/**
* @dataProvider providerFractions
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerFractions')]
public function testFraction(string $expected, string $value): void
{
$originalValue = $value;
Expand All @@ -60,9 +56,7 @@ public static function providerFractions(): array
];
}

/**
* @dataProvider providerPercentages
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerPercentages')]
public function testPercentage(string $expected, string $value): void
{
$originalValue = $value;
Expand Down Expand Up @@ -189,9 +183,7 @@ public static function providerPercentages(): array
];
}

/**
* @dataProvider providerCurrencies
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerCurrencies')]
public function testCurrencies(string $expected, string $value): void
{
$originalValue = $value;
Expand Down
15 changes: 4 additions & 11 deletions tests/PhpSpreadsheetTests/Calculation/Engine/RangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ protected function tearDown(): void
}
}

/**
* @dataProvider providerRangeEvaluation
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerRangeEvaluation')]
public function testRangeEvaluation(string $formula, int|string $expectedResult): void
{
$this->spreadSheet = $this->getSpreadsheet();
Expand Down Expand Up @@ -97,9 +95,7 @@ public function test3dRangeEvaluation(): void
$workSheet->getCell('E1')->getCalculatedValue();
}

/**
* @dataProvider providerNamedRangeEvaluation
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerNamedRangeEvaluation')]
public function testNamedRangeEvaluation(array $ranges, string $formula, int $expectedResult): void
{
$this->spreadSheet = $this->getSpreadsheet();
Expand Down Expand Up @@ -134,11 +130,10 @@ public static function providerNamedRangeEvaluation(): array
}

/**
* @dataProvider providerUTF8NamedRangeEvaluation
*
* @param string[] $names
* @param string[] $ranges
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerUTF8NamedRangeEvaluation')]
public function testUTF8NamedRangeEvaluation(array $names, array $ranges, string $formula, int $expectedResult): void
{
$this->spreadSheet = $this->getSpreadsheet();
Expand All @@ -162,9 +157,7 @@ public static function providerUTF8NamedRangeEvaluation(): array
];
}

/**
* @dataProvider providerCompositeNamedRangeEvaluation
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerCompositeNamedRangeEvaluation')]
public function testCompositeNamedRangeEvaluation(string $composite, int $expectedSum, int $expectedCount): void
{
if ($this->incompleteMessage !== '') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ protected function tearDown(): void
parent::tearDown();
}

/**
* @dataProvider structuredReferenceProviderColumnData
*/
#[\PHPUnit\Framework\Attributes\DataProvider('structuredReferenceProviderColumnData')]
public function testStructuredReferenceColumns(string $expectedCellRange, string $structuredReference): void
{
$spreadsheet = $this->getSpreadsheet();
Expand All @@ -65,9 +63,7 @@ public function testStructuredReferenceColumns(string $expectedCellRange, string
self::assertSame($expectedCellRange, $cellRange);
}

/**
* @dataProvider structuredReferenceProviderRowData
*/
#[\PHPUnit\Framework\Attributes\DataProvider('structuredReferenceProviderRowData')]
public function testStructuredReferenceRows(string $expectedCellRange, string $structuredReference): void
{
$spreadsheet = $this->getSpreadsheet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public function testStructuredReferenceInvalidCellForTable(): void
$structuredReferenceObject->parse($cell);
}

/**
* @dataProvider structuredReferenceProviderColumnData
*/
#[\PHPUnit\Framework\Attributes\DataProvider('structuredReferenceProviderColumnData')]
public function testStructuredReferenceColumns(string $expectedCellRange, string $structuredReference): void
{
$cell = $this->spreadSheet->getActiveSheet()->getCell('E5');
Expand All @@ -82,9 +80,7 @@ public function testStructuredReferenceColumns(string $expectedCellRange, string
self::assertSame($expectedCellRange, $cellRange);
}

/**
* @dataProvider structuredReferenceProviderRowData
*/
#[\PHPUnit\Framework\Attributes\DataProvider('structuredReferenceProviderRowData')]
public function testStructuredReferenceRows(string $expectedCellRange, string $structuredReference): void
{
$cell = $this->spreadSheet->getActiveSheet()->getCell('E5');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@

class FormulaAsStringTest extends TestCase
{
/**
* @dataProvider providerFunctionsAsString
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerFunctionsAsString')]
public function testFunctionsAsString(mixed $expectedResult, string $formula): void
{
$spreadsheet = new Spreadsheet();
Expand Down
4 changes: 1 addition & 3 deletions tests/PhpSpreadsheetTests/Calculation/FormulaParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public function testNoFormula(): void
self::assertSame(0, $result->getTokenCount());
}

/**
* @dataProvider providerFormulaParser
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerFormulaParser')]
public function testFormulaParser(string $formula, array $expectedResult): void
{
$formula = "=$formula";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@

class DAverageTest extends SetupTeardownDatabases
{
/**
* @dataProvider providerDAverage
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerDAverage')]
public function testDirectCallToDAverage(int|float|string $expectedResult, array $database, string|int|null $field, array $criteria): void
{
$result = DAverage::evaluate($database, $field, $criteria);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}

/**
* @dataProvider providerDAverage
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerDAverage')]
public function testDAverageAsWorksheetFormula(int|float|string $expectedResult, array $database, string|int|null $field, array $criteria): void
{
$this->prepareWorksheetWithFormula('DAVERAGE', $database, $field, $criteria);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,14 @@

class DCountATest extends SetupTeardownDatabases
{
/**
* @dataProvider providerDCountA
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerDCountA')]
public function testDirectCallToDCountA(int|string $expectedResult, array $database, string $field, array $criteria): void
{
$result = DCountA::evaluate($database, $field, $criteria);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}

/**
* @dataProvider providerDCountA
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerDCountA')]
public function testDCountAAsWorksheetFormula(int|string $expectedResult, array $database, string $field, array $criteria): void
{
$this->prepareWorksheetWithFormula('DCOUNTA', $database, $field, $criteria);
Expand Down
Loading

0 comments on commit a70b335

Please sign in to comment.