Skip to content

Commit

Permalink
Closes #4603
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 9, 2021
1 parent 19f170b commit 642ca8b
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 12 deletions.
1 change: 1 addition & 0 deletions ChangeLog-10.0.md
Expand Up @@ -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 `<test>` elements in the TestDox XML logfile now contains a textual representation instead of a number (`"success"` instead of `"0"`, for instance)
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xsd
Expand Up @@ -202,7 +202,7 @@
</xs:complexType>
<xs:attributeGroup name="configAttributeGroup">
<xs:attribute name="backupGlobals" type="xs:boolean" default="false"/>
<xs:attribute name="backupStaticAttributes" type="xs:boolean" default="false"/>
<xs:attribute name="backupStaticProperties" type="xs:boolean" default="false"/>
<xs:attribute name="bootstrap" type="xs:anyURI"/>
<xs:attribute name="cacheDirectory" type="xs:anyURI"/>
<xs:attribute name="cacheResult" type="xs:boolean" default="true"/>
Expand Down
2 changes: 1 addition & 1 deletion src/TextUI/Help.php
Expand Up @@ -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 <flag>', 'desc' => 'Use colors in output ("never", "auto" or "always")'],
Expand Down
2 changes: 1 addition & 1 deletion src/TextUI/TestRunner.php
Expand Up @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion src/TextUI/XmlConfiguration/Loader.php
Expand Up @@ -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),
Expand Down Expand Up @@ -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
);
Expand Down
1 change: 1 addition & 0 deletions src/TextUI/XmlConfiguration/Migration/MigrationBuilder.php
Expand Up @@ -46,6 +46,7 @@ final class MigrationBuilder
RemoveCacheResultFileAttribute::class,
RemoveCoverageElementCacheDirectoryAttribute::class,
IntroduceCacheDirectoryAttribute::class,
RenameBackupStaticAttributesAttribute::class,
],
];

Expand Down
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* 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'));
}
}
10 changes: 5 additions & 5 deletions src/TextUI/XmlConfiguration/PHPUnit/PHPUnit.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/cli/_files/output-cli-help-color.txt
Expand Up @@ -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 <flag>  Use colors in output ("never", "auto" or
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/cli/_files/output-cli-usage.txt
Expand Up @@ -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 <flag> Use colors in output ("never", "auto" or "always")
--columns <n> Number of columns to use for progress output
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/TextUI/XmlConfigurationTest.php
Expand Up @@ -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());
Expand Down

0 comments on commit 642ca8b

Please sign in to comment.