Skip to content

Commit a3d11a9

Browse files
authored
Merge pull request #576 from PHPCSStandards/feature/configdouble-stabilize
Tests: stability tweaks for the non-sniff tests
2 parents 329ad21 + 6b7cc9d commit a3d11a9

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

tests/ConfigDouble.php

+16
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,22 @@ public function __construct(array $cliArgs=[], $skipSettingStandard=false, $skip
7272
}//end __construct()
7373

7474

75+
/**
76+
* Ensures the static properties in the Config class are reset to their default values
77+
* when the ConfigDouble is no longer used.
78+
*
79+
* @return void
80+
*/
81+
public function __destruct()
82+
{
83+
$this->setStaticConfigProperty('overriddenDefaults', []);
84+
$this->setStaticConfigProperty('executablePaths', []);
85+
$this->setStaticConfigProperty('configData', null);
86+
$this->setStaticConfigProperty('configDataFile', null);
87+
88+
}//end __destruct()
89+
90+
7591
/**
7692
* Sets the command line values and optionally prevents a file system search for a custom ruleset.
7793
*

tests/Core/AbstractMethodUnitTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,33 @@ public static function initializeFile()
8080
}//end initializeFile()
8181

8282

83+
/**
84+
* Clean up after finished test by resetting all static properties on the class to their default values.
85+
*
86+
* Note: This is a PHPUnit cross-version compatible {@see \PHPUnit\Framework\TestCase::tearDownAfterClass()}
87+
* method.
88+
*
89+
* @afterClass
90+
*
91+
* @return void
92+
*/
93+
public static function reset()
94+
{
95+
// Explicitly trigger __destruct() on the ConfigDouble to reset the Config statics.
96+
// The explicit method call prevents potential stray test-local references to the $config object
97+
// preventing the destructor from running the clean up (which without stray references would be
98+
// automagically triggered when `self::$phpcsFile` is reset, but we can't definitively rely on that).
99+
if (isset(self::$phpcsFile) === true) {
100+
self::$phpcsFile->config->__destruct();
101+
}
102+
103+
self::$fileExtension = 'inc';
104+
self::$tabWidth = 4;
105+
self::$phpcsFile = null;
106+
107+
}//end reset()
108+
109+
83110
/**
84111
* Get the token pointer for a target token based on a specific comment found on the line before.
85112
*

tests/Core/Filters/AbstractFilterTestCase.php

+23
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@ public static function initializeConfigAndRuleset()
5151
}//end initializeConfigAndRuleset()
5252

5353

54+
/**
55+
* Clean up after finished test by resetting all static properties on the Config class to their default values.
56+
*
57+
* Note: This is a PHPUnit cross-version compatible {@see \PHPUnit\Framework\TestCase::tearDownAfterClass()}
58+
* method.
59+
*
60+
* @afterClass
61+
*
62+
* @return void
63+
*/
64+
public static function reset()
65+
{
66+
// Explicitly trigger __destruct() on the ConfigDouble to reset the Config statics.
67+
// The explicit method call prevents potential stray test-local references to the $config object
68+
// preventing the destructor from running the clean up (which without stray references would be
69+
// automagically triggered when `self::$phpcsFile` is reset, but we can't definitively rely on that).
70+
if (isset(self::$config) === true) {
71+
self::$config->__destruct();
72+
}
73+
74+
}//end reset()
75+
76+
5477
/**
5578
* Helper method to retrieve a mock object for a Filter class.
5679
*

0 commit comments

Comments
 (0)