Skip to content

Commit 3d54d4c

Browse files
committed
Config: remove more test specific conditions
The `--cache` option could not be tested as the `Config` class did not allow for it to be set in a test situation. This "conditional ignore" was introduced in commit 24c7a7f around the same time the caching feature was introduced. The commit message doesn't give a reason for introducing the conditional ignore. I can only guess why and my guess would be that it was to prevent test runs being influence by dev-user specific system-wide defaults from a `CodeSniffer.conf` file. In my opinion, that is not a good reason for keeping the "conditional ignore". * First of all, the default setting is for the cache to be _off_, so by default, tests wouldn't use the cache anyhow. * Second of all, the problem of interference from dev-user specific system-wide defaults was fixed by the introduction of the `ConfigDouble` and the `AbstractRealConfigTestCase`. All in all, I think these conditions can be safely removed. Do keep in mind though that subsequent test runs for tests involving caching may re-use the cache from an earlier run test. To prevent that, set an explicit cacheFile for the test using `--cache=<filename>` and remove this cache file after running the test(s) via the `tearDown[AfterClass]()` method. Note: one of the removed conditions also affected the `--parallel` option, but only for system-wide settings, not for CLI arguments. Related to 966
1 parent 19d4bb8 commit 3d54d4c

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/Config.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -650,16 +650,14 @@ public function restoreDefaults()
650650
$this->colors = (bool) $colors;
651651
}
652652

653-
if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
654-
$cache = self::getConfigData('cache');
655-
if ($cache !== null) {
656-
$this->cache = (bool) $cache;
657-
}
653+
$cache = self::getConfigData('cache');
654+
if ($cache !== null) {
655+
$this->cache = (bool) $cache;
656+
}
658657

659-
$parallel = self::getConfigData('parallel');
660-
if ($parallel !== null) {
661-
$this->parallel = max((int) $parallel, 1);
662-
}
658+
$parallel = self::getConfigData('parallel');
659+
if ($parallel !== null) {
660+
$this->parallel = max((int) $parallel, 1);
663661
}
664662

665663
}//end restoreDefaults()
@@ -817,10 +815,8 @@ public function processLongArgument($arg, $pos)
817815
break;
818816
}
819817

820-
if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
821-
$this->cache = true;
822-
$this->overriddenDefaults['cache'] = true;
823-
}
818+
$this->cache = true;
819+
$this->overriddenDefaults['cache'] = true;
824820
break;
825821
case 'no-cache':
826822
if (isset($this->overriddenDefaults['cache']) === true) {
@@ -928,9 +924,7 @@ public function processLongArgument($arg, $pos)
928924

929925
$this->exclude = $this->parseSniffCodes(substr($arg, 8), 'exclude');
930926
$this->overriddenDefaults['exclude'] = true;
931-
} else if (defined('PHP_CODESNIFFER_IN_TESTS') === false
932-
&& substr($arg, 0, 6) === 'cache='
933-
) {
927+
} else if (substr($arg, 0, 6) === 'cache=') {
934928
if ((isset($this->overriddenDefaults['cache']) === true
935929
&& $this->cache === false)
936930
|| isset($this->overriddenDefaults['cacheFile']) === true

0 commit comments

Comments
 (0)