Skip to content

Commit 559d47e

Browse files
committed
Tests: minor stability tweak
Follow up on 275 While tests should always clean up after themselves, this little tweak at least prevents tests which set the `$_SERVER` global (and don't reset it after the test is finished) from influencing tests which use these abstract test cases. _Explanation: the `$_SERVER` global is not automatically reset between tests by PHPUnit and the `Config` class _will_ read it out when it is set, so if one tests set the global and doesn't reset it, the next test with get a `Config` instance which will use the args set in the `$_SERVER['argv']` from the previous test._
1 parent fa15cdd commit 559d47e

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

tests/Core/AbstractMethodUnitTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ abstract class AbstractMethodUnitTest extends TestCase
5757
*/
5858
public static function initializeFile()
5959
{
60-
$config = new ConfigDouble();
60+
$_SERVER['argv'] = [];
61+
$config = new ConfigDouble();
6162
// Also set a tab-width to enable testing tab-replaced vs `orig_content`.
6263
$config->tabWidth = static::$tabWidth;
6364

tests/Core/Tokenizer/AbstractTokenizerTestCase.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ abstract class AbstractTokenizerTestCase extends TestCase
6262
protected function initializeFile()
6363
{
6464
if (isset($this->phpcsFile) === false) {
65-
$config = new ConfigDouble();
65+
$_SERVER['argv'] = [];
66+
$config = new ConfigDouble();
67+
6668
// Also set a tab-width to enable testing tab-replaced vs `orig_content`.
6769
$config->tabWidth = $this->tabWidth;
6870

@@ -79,7 +81,7 @@ protected function initializeFile()
7981

8082
$this->phpcsFile = new DummyFile($contents, $ruleset, $config);
8183
$this->phpcsFile->parse();
82-
}
84+
}//end if
8385

8486
}//end initializeFile()
8587

0 commit comments

Comments
 (0)