diff --git a/ChangeLog-10.0.md b/ChangeLog-10.0.md index 7f5b9ed993a..fa5c156660c 100644 --- a/ChangeLog-10.0.md +++ b/ChangeLog-10.0.md @@ -8,6 +8,7 @@ All notable changes of the PHPUnit 10.0 release series are documented in this fi * [#3871](https://github.com/sebastianbergmann/phpunit/issues/3871): Declare return types for `InvocationStubber` methods * [#4599](https://github.com/sebastianbergmann/phpunit/issues/4599): Unify cache configuration +* [#4603](https://github.com/sebastianbergmann/phpunit/issues/4603): Use "property" instead of "attribute" for configuring the backup of static fields * PHPUnit no longer invokes a static method named `suite` on a class that is declared in a file that is passed as an argument to the CLI test runner * PHPUnit no longer promotes variables that are global in the bootstrap script's scope to global variables in the test runner's scope (use `$GLOBALS['variable'] = 'value'` instead of `$variable = 'value'` in your bootstrap script) * The `status` attribute of `` elements in the TestDox XML logfile now contains a textual representation instead of a number (`"success"` instead of `"0"`, for instance) diff --git a/phpunit.xsd b/phpunit.xsd index 8d6c98291f4..f642195f271 100644 --- a/phpunit.xsd +++ b/phpunit.xsd @@ -202,7 +202,7 @@ - + diff --git a/src/TextUI/Help.php b/src/TextUI/Help.php index b7d6219c60c..b099ceba23d 100644 --- a/src/TextUI/Help.php +++ b/src/TextUI/Help.php @@ -86,7 +86,7 @@ final class Help ['arg' => '--process-isolation', 'desc' => 'Run each test in a separate PHP process'], ['arg' => '--globals-backup', 'desc' => 'Backup and restore $GLOBALS for each test'], - ['arg' => '--static-backup', 'desc' => 'Backup and restore static attributes for each test'], + ['arg' => '--static-backup', 'desc' => 'Backup and restore static properties for each test'], ['spacer' => ''], ['arg' => '--colors ', 'desc' => 'Use colors in output ("never", "auto" or "always")'], diff --git a/src/TextUI/TestRunner.php b/src/TextUI/TestRunner.php index 6eaa481126c..9da4dafad1e 100644 --- a/src/TextUI/TestRunner.php +++ b/src/TextUI/TestRunner.php @@ -863,7 +863,7 @@ private function handleConfiguration(array &$arguments): void $phpunitConfiguration = $arguments['configurationObject']->phpunit(); $arguments['backupGlobals'] = $arguments['backupGlobals'] ?? $phpunitConfiguration->backupGlobals(); - $arguments['backupStaticAttributes'] = $arguments['backupStaticAttributes'] ?? $phpunitConfiguration->backupStaticAttributes(); + $arguments['backupStaticAttributes'] = $arguments['backupStaticAttributes'] ?? $phpunitConfiguration->backupStaticProperties(); $arguments['beStrictAboutChangesToGlobalState'] = $arguments['beStrictAboutChangesToGlobalState'] ?? $phpunitConfiguration->beStrictAboutChangesToGlobalState(); $arguments['cacheResult'] = $arguments['cacheResult'] ?? $phpunitConfiguration->cacheResult(); $arguments['colors'] = $arguments['colors'] ?? $phpunitConfiguration->colors(); diff --git a/src/TextUI/XmlConfiguration/Loader.php b/src/TextUI/XmlConfiguration/Loader.php index 6b6fc9eb1ba..2a789c9ba43 100644 --- a/src/TextUI/XmlConfiguration/Loader.php +++ b/src/TextUI/XmlConfiguration/Loader.php @@ -792,6 +792,14 @@ private function phpunit(string $filename, DOMDocument $document): PHPUnit $printerFile = $this->toAbsolutePath($filename, $printerFile); } + $backupStaticProperties = false; + + if ($document->documentElement->hasAttribute('backupStaticProperties')) { + $backupStaticProperties = $this->getBooleanAttribute($document->documentElement, 'backupStaticProperties', false); + } elseif ($document->documentElement->hasAttribute('backupStaticAttributes')) { + $backupStaticProperties = $this->getBooleanAttribute($document->documentElement, 'backupStaticAttributes', false); + } + return new PHPUnit( $cacheDirectory, $this->getBooleanAttribute($document->documentElement, 'cacheResult', true), @@ -840,7 +848,7 @@ private function phpunit(string $filename, DOMDocument $document): PHPUnit $resolveDependencies, $defectsFirst, $this->getBooleanAttribute($document->documentElement, 'backupGlobals', false), - $this->getBooleanAttribute($document->documentElement, 'backupStaticAttributes', false), + $backupStaticProperties, $this->getBooleanAttribute($document->documentElement, 'registerMockObjectsFromTestArgumentsRecursively', false), $conflictBetweenPrinterClassAndTestdox ); diff --git a/src/TextUI/XmlConfiguration/Migration/MigrationBuilder.php b/src/TextUI/XmlConfiguration/Migration/MigrationBuilder.php index 10234526769..139ff273ef7 100644 --- a/src/TextUI/XmlConfiguration/Migration/MigrationBuilder.php +++ b/src/TextUI/XmlConfiguration/Migration/MigrationBuilder.php @@ -46,6 +46,7 @@ final class MigrationBuilder RemoveCacheResultFileAttribute::class, RemoveCoverageElementCacheDirectoryAttribute::class, IntroduceCacheDirectoryAttribute::class, + RenameBackupStaticAttributesAttribute::class, ], ]; diff --git a/src/TextUI/XmlConfiguration/Migration/Migrations/RenameBackupStaticAttributesAttribute.php b/src/TextUI/XmlConfiguration/Migration/Migrations/RenameBackupStaticAttributesAttribute.php new file mode 100644 index 00000000000..5292d51f9c1 --- /dev/null +++ b/src/TextUI/XmlConfiguration/Migration/Migrations/RenameBackupStaticAttributesAttribute.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\TextUI\XmlConfiguration; + +use DOMDocument; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class RenameBackupStaticAttributesAttribute implements Migration +{ + public function migrate(DOMDocument $document): void + { + $root = $document->documentElement; + + if ($root->hasAttribute('backupStaticProperties')) { + return; + } + + if (!$root->hasAttribute('backupStaticAttributes')) { + return; + } + + $root->setAttribute('backupStaticProperties', $root->getAttribute('backupStaticAttributes')); + } +} diff --git a/src/TextUI/XmlConfiguration/PHPUnit/PHPUnit.php b/src/TextUI/XmlConfiguration/PHPUnit/PHPUnit.php index bef3971e531..5cc43f61b68 100644 --- a/src/TextUI/XmlConfiguration/PHPUnit/PHPUnit.php +++ b/src/TextUI/XmlConfiguration/PHPUnit/PHPUnit.php @@ -112,13 +112,13 @@ final class PHPUnit private bool $backupGlobals; - private bool $backupStaticAttributes; + private bool $backupStaticProperties; private bool $registerMockObjectsFromTestArgumentsRecursively; private bool $conflictBetweenPrinterClassAndTestdox; - public function __construct(?string $cacheDirectory, bool $cacheResult, ?string $cacheResultFile, $columns, string $colors, bool $stderr, bool $noInteraction, bool $verbose, bool $reverseDefectList, bool $convertDeprecationsToExceptions, bool $convertErrorsToExceptions, bool $convertNoticesToExceptions, bool $convertWarningsToExceptions, bool $forceCoversAnnotation, ?string $bootstrap, bool $processIsolation, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $stopOnDefect, bool $stopOnError, bool $stopOnFailure, bool $stopOnWarning, bool $stopOnIncomplete, bool $stopOnRisky, bool $stopOnSkipped, ?string $extensionsDirectory, ?string $printerClass, ?string $printerFile, bool $beStrictAboutChangesToGlobalState, bool $beStrictAboutOutputDuringTests, bool $beStrictAboutResourceUsageDuringSmallTests, bool $beStrictAboutTestsThatDoNotTestAnything, bool $beStrictAboutTodoAnnotatedTests, bool $beStrictAboutCoversAnnotation, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, ?string $defaultTestSuite, int $executionOrder, bool $resolveDependencies, bool $defectsFirst, bool $backupGlobals, bool $backupStaticAttributes, bool $registerMockObjectsFromTestArgumentsRecursively, bool $conflictBetweenPrinterClassAndTestdox) + public function __construct(?string $cacheDirectory, bool $cacheResult, ?string $cacheResultFile, $columns, string $colors, bool $stderr, bool $noInteraction, bool $verbose, bool $reverseDefectList, bool $convertDeprecationsToExceptions, bool $convertErrorsToExceptions, bool $convertNoticesToExceptions, bool $convertWarningsToExceptions, bool $forceCoversAnnotation, ?string $bootstrap, bool $processIsolation, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $stopOnDefect, bool $stopOnError, bool $stopOnFailure, bool $stopOnWarning, bool $stopOnIncomplete, bool $stopOnRisky, bool $stopOnSkipped, ?string $extensionsDirectory, ?string $printerClass, ?string $printerFile, bool $beStrictAboutChangesToGlobalState, bool $beStrictAboutOutputDuringTests, bool $beStrictAboutResourceUsageDuringSmallTests, bool $beStrictAboutTestsThatDoNotTestAnything, bool $beStrictAboutTodoAnnotatedTests, bool $beStrictAboutCoversAnnotation, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, ?string $defaultTestSuite, int $executionOrder, bool $resolveDependencies, bool $defectsFirst, bool $backupGlobals, bool $backupStaticProperties, bool $registerMockObjectsFromTestArgumentsRecursively, bool $conflictBetweenPrinterClassAndTestdox) { $this->cacheDirectory = $cacheDirectory; $this->cacheResult = $cacheResult; @@ -167,7 +167,7 @@ public function __construct(?string $cacheDirectory, bool $cacheResult, ?string $this->resolveDependencies = $resolveDependencies; $this->defectsFirst = $defectsFirst; $this->backupGlobals = $backupGlobals; - $this->backupStaticAttributes = $backupStaticAttributes; + $this->backupStaticProperties = $backupStaticProperties; $this->registerMockObjectsFromTestArgumentsRecursively = $registerMockObjectsFromTestArgumentsRecursively; $this->conflictBetweenPrinterClassAndTestdox = $conflictBetweenPrinterClassAndTestdox; } @@ -516,9 +516,9 @@ public function backupGlobals(): bool return $this->backupGlobals; } - public function backupStaticAttributes(): bool + public function backupStaticProperties(): bool { - return $this->backupStaticAttributes; + return $this->backupStaticProperties; } public function registerMockObjectsFromTestArgumentsRecursively(): bool diff --git a/tests/end-to-end/cli/_files/output-cli-help-color.txt b/tests/end-to-end/cli/_files/output-cli-help-color.txt index 62af28d8815..636dae94544 100644 --- a/tests/end-to-end/cli/_files/output-cli-help-color.txt +++ b/tests/end-to-end/cli/_files/output-cli-help-color.txt @@ -70,7 +70,7 @@ --process-isolation  Run each test in a separate PHP process --globals-backup  Backup and restore $GLOBALS for each test - --static-backup  Backup and restore static attributes for + --static-backup  Backup and restore static properties for each test --colors   Use colors in output ("never", "auto" or diff --git a/tests/end-to-end/cli/_files/output-cli-usage.txt b/tests/end-to-end/cli/_files/output-cli-usage.txt index 2562930047d..dd7c1c7eee8 100644 --- a/tests/end-to-end/cli/_files/output-cli-usage.txt +++ b/tests/end-to-end/cli/_files/output-cli-usage.txt @@ -56,7 +56,7 @@ Test Execution Options: --process-isolation Run each test in a separate PHP process --globals-backup Backup and restore $GLOBALS for each test - --static-backup Backup and restore static attributes for each test + --static-backup Backup and restore static properties for each test --colors Use colors in output ("never", "auto" or "always") --columns Number of columns to use for progress output diff --git a/tests/unit/TextUI/XmlConfigurationTest.php b/tests/unit/TextUI/XmlConfigurationTest.php index ca61ee0b835..94fe9d42f80 100644 --- a/tests/unit/TextUI/XmlConfigurationTest.php +++ b/tests/unit/TextUI/XmlConfigurationTest.php @@ -480,7 +480,7 @@ public function testPHPUnitConfigurationIsReadCorrectly(): void $phpunit = $this->configuration('configuration.xml')->phpunit(); $this->assertTrue($phpunit->backupGlobals()); - $this->assertFalse($phpunit->backupStaticAttributes()); + $this->assertFalse($phpunit->backupStaticProperties()); $this->assertFalse($phpunit->beStrictAboutChangesToGlobalState()); $this->assertSame('/path/to/bootstrap.php', $phpunit->bootstrap()); $this->assertSame(80, $phpunit->columns());