Skip to content

Commit d647fe7

Browse files
committed
Use Php Attributes Rather than Annotations for PhpUnit
With PhpUnit 10 came the ability to use Php attributes rather than doc-block annotations for things like "data provider". PhpUnit 11 deprecates the use of annotations, and PhpUnit 12 will not not permit their use. Since PhpUnit 11 requires Php8.2+, we cannot adopt it as long as we support Php8.1, which will continue to be the case for some time. However, there is no penalty for early adoption. Php-cs-fixer can use: ``` 'php_unit_attributes' => ['keep_annotations' => false], ``` This allows us to run `composer fix` to automate all the needed changes. No manual changes were needed for any of the test members. With this change, PhpUnit 9 can no longer be used with the test suite. File composer.json is updated to reflect that reality, and phpunit9.xml.dist, which has been supplied in case anyone needed to use PhpUnit 9, is no longer required, and is thus deleted. For now, PhpUnit 11 is not being added as a possibility. No source code is changed in this PR.
1 parent f37b119 commit d647fe7

File tree

549 files changed

+1263
-3742
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

549 files changed

+1263
-3742
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
'ordered_imports' => true,
147147
'ordered_interfaces' => true,
148148
'ordered_traits' => true,
149+
'php_unit_attributes' => ['keep_annotations' => false],
149150
'php_unit_construct' => true,
150151
'php_unit_dedicate_assert' => true,
151152
'php_unit_dedicate_assert_internal_type' => true,

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ This makes it easier to see exactly what is being tested when reviewing the PR.
4040
2. Tag subject must be the version number, eg: `1.2.3`
4141
3. Tag body must be a copy-paste of the changelog entries.
4242
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.
43-
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 ';'`.
43+
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 ";"`.
4444

4545
> **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.
4646
- release1291

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"phpcompatibility/php-compatibility": "^9.3",
9696
"phpstan/phpstan": "^1.1",
9797
"phpstan/phpstan-phpunit": "^1.0",
98-
"phpunit/phpunit": "^9.6 || ^10.5",
98+
"phpunit/phpunit": "^10.5",
9999
"squizlabs/php_codesniffer": "^3.7",
100100
"tecnickcom/tcpdf": "^6.5"
101101
},

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<coverage/>
44
<php>
55
<ini name="memory_limit" value="2048M"/>
6+
<ini name="error_reporting" value="E_ALL"/>
67
</php>
78
<testsuite name="PhpSpreadsheet Unit Test Suite">
89
<directory>./tests/PhpSpreadsheetTests</directory>

phpunit9.xml.dist

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/PhpSpreadsheetTests/Calculation/ArrayFormulaTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
class ArrayFormulaTest extends TestCase
1212
{
13-
/**
14-
* @dataProvider providerArrayFormulae
15-
*/
13+
#[\PHPUnit\Framework\Attributes\DataProvider('providerArrayFormulae')]
1614
public function testArrayFormula(string $formula, mixed $expectedResult): void
1715
{
1816
$result = Calculation::getInstance()->_calculateFormulaValue($formula);

tests/PhpSpreadsheetTests/Calculation/BinaryComparisonTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ protected function tearDown(): void
2424
Functions::setCompatibilityMode($this->compatibilityMode);
2525
}
2626

27-
/**
28-
* @dataProvider providerBinaryComparison
29-
*/
27+
#[\PHPUnit\Framework\Attributes\DataProvider('providerBinaryComparison')]
3028
public function testBinaryComparisonOperation(
3129
mixed $operand1,
3230
mixed $operand2,

tests/PhpSpreadsheetTests/Calculation/CalculationFunctionListTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ protected function tearDown(): void
2424
Functions::setCompatibilityMode($this->compatibilityMode);
2525
}
2626

27-
/**
28-
* @dataProvider providerGetFunctions
29-
*/
27+
#[\PHPUnit\Framework\Attributes\DataProvider('providerGetFunctions')]
3028
public function testGetFunctions(array|string $functionCall): void
3129
{
3230
self::assertIsCallable($functionCall);

tests/PhpSpreadsheetTests/Calculation/CalculationSettingsTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ protected function tearDown(): void
2929
$calculation->setLocale($this->locale);
3030
}
3131

32-
/**
33-
* @dataProvider providerCanLoadAllSupportedLocales
34-
*/
32+
#[\PHPUnit\Framework\Attributes\DataProvider('providerCanLoadAllSupportedLocales')]
3533
public function testCanLoadAllSupportedLocales(string $locale): void
3634
{
3735
$calculation = Calculation::getInstance();

tests/PhpSpreadsheetTests/Calculation/CalculationTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ protected function tearDown(): void
2727
Functions::setCompatibilityMode($this->compatibilityMode);
2828
}
2929

30-
/**
31-
* @dataProvider providerBinaryComparisonOperation
32-
*/
30+
#[\PHPUnit\Framework\Attributes\DataProvider('providerBinaryComparisonOperation')]
3331
public function testBinaryComparisonOperation(string $formula, mixed $expectedResultExcel, mixed $expectedResultOpenOffice): void
3432
{
3533
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
@@ -374,9 +372,8 @@ public function testBranchPruningFormulaParsingInequalitiesConditionsCase(): voi
374372
* be set in cache
375373
* @param string[] $shouldNotBeSetInCacheCells coordinates of cells that must
376374
* not be set in cache because of pruning
377-
*
378-
* @dataProvider dataProviderBranchPruningFullExecution
379375
*/
376+
#[\PHPUnit\Framework\Attributes\DataProvider('dataProviderBranchPruningFullExecution')]
380377
public function testFullExecutionDataPruning(
381378
mixed $expectedResult,
382379
array $dataArray,

0 commit comments

Comments
 (0)