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.
This commit is contained in:
oleibman
2024-11-23 20:56:26 -08:00
parent f37b119298
commit d647fe7ee7
549 changed files with 1263 additions and 3742 deletions
@@ -26,9 +26,7 @@ class Dec2OctTest extends TestCase
Functions::setCompatibilityMode($this->compatibilityMode);
}
/**
* @dataProvider providerDEC2OCT
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerDEC2OCT')]
public function testDirectCallToDEC2OCT(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void
{
$result = ($digits === null) ? ConvertDecimal::toOctal($value) : ConvertDecimal::toOctal($value, $digits);
@@ -40,9 +38,7 @@ class Dec2OctTest extends TestCase
return trim($value, '"');
}
/**
* @dataProvider providerDEC2OCT
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerDEC2OCT')]
public function testDEC2OCTAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
@@ -55,9 +51,7 @@ class Dec2OctTest extends TestCase
self::assertSame($expectedResult, $this->trimIfQuoted((string) $result));
}
/**
* @dataProvider providerDEC2OCT
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerDEC2OCT')]
public function testDEC2OCTInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
@@ -80,9 +74,7 @@ class Dec2OctTest extends TestCase
return require 'tests/data/Calculation/Engineering/DEC2OCT.php';
}
/**
* @dataProvider providerUnhappyDEC2OCT
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerUnhappyDEC2OCT')]
public function testDEC2OCTUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
@@ -108,9 +100,7 @@ class Dec2OctTest extends TestCase
];
}
/**
* @dataProvider providerDEC2OCTOds
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerDEC2OCTOds')]
public function testDEC2OCTOds(mixed $expectedResult, bool|float|int|string $value, ?int $digits = null): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
@@ -145,9 +135,7 @@ class Dec2OctTest extends TestCase
self::assertSame('21', $this->trimIfQuoted((string) $result), 'Excel');
}
/**
* @dataProvider providerDec2OctArray
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerDec2OctArray')]
public function testDec2OctArray(array $expectedResult, string $value): void
{
$calculation = Calculation::getInstance();