From 559d47ecfa84ec6e9065fed1ffca55c3e909f7cd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 20 Feb 2024 18:11:42 +0100 Subject: [PATCH] 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._ --- tests/Core/AbstractMethodUnitTest.php | 3 ++- tests/Core/Tokenizer/AbstractTokenizerTestCase.php | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/Core/AbstractMethodUnitTest.php b/tests/Core/AbstractMethodUnitTest.php index 258f0b35fb..b933be17b4 100644 --- a/tests/Core/AbstractMethodUnitTest.php +++ b/tests/Core/AbstractMethodUnitTest.php @@ -57,7 +57,8 @@ abstract class AbstractMethodUnitTest extends TestCase */ public static function initializeFile() { - $config = new ConfigDouble(); + $_SERVER['argv'] = []; + $config = new ConfigDouble(); // Also set a tab-width to enable testing tab-replaced vs `orig_content`. $config->tabWidth = static::$tabWidth; diff --git a/tests/Core/Tokenizer/AbstractTokenizerTestCase.php b/tests/Core/Tokenizer/AbstractTokenizerTestCase.php index c9e09c07d4..0f829182ba 100644 --- a/tests/Core/Tokenizer/AbstractTokenizerTestCase.php +++ b/tests/Core/Tokenizer/AbstractTokenizerTestCase.php @@ -62,7 +62,9 @@ abstract class AbstractTokenizerTestCase extends TestCase protected function initializeFile() { if (isset($this->phpcsFile) === false) { - $config = new ConfigDouble(); + $_SERVER['argv'] = []; + $config = new ConfigDouble(); + // Also set a tab-width to enable testing tab-replaced vs `orig_content`. $config->tabWidth = $this->tabWidth; @@ -79,7 +81,7 @@ protected function initializeFile() $this->phpcsFile = new DummyFile($contents, $ruleset, $config); $this->phpcsFile->parse(); - } + }//end if }//end initializeFile()