Skip to content

Commit bb6de7b

Browse files
committed
Unit tests: set the PHPCS_IGNORE_TESTS environment variable from the bootstrap
... which makes it independent of the dev environment of individual devs, making it more stable and less fiddly.
1 parent b1af253 commit bb6de7b

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

phpunit-bootstrap.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
if ($phpcsDir !== false && \is_dir($phpcsDir)) {
4242
if (\file_exists($phpcsDir . $ds . 'tests' . $ds . 'bootstrap.php')) {
4343
require_once $phpcsDir . $ds . 'tests' . $ds . 'bootstrap.php'; // PHPUnit 6.x+ support as of PHPCS 3.1.0.
44+
} elseif (\file_exists($phpcsDir . $ds . 'autoload.php')) {
45+
require_once $phpcsDir . $ds . 'autoload.php'; // PHPCS < 3.1.0.
4446
}
4547
} else {
4648
echo 'Uh oh... can\'t find PHPCS.
@@ -53,5 +55,29 @@
5355
die(1);
5456
}
5557

58+
/*
59+
* Set the PHPCS_IGNORE_TEST environment variable to ignore tests from other standards.
60+
* Ref: https://github.com/squizlabs/PHP_CodeSniffer/pull/1146
61+
*/
62+
$phpcsDevtoolsStandards = [
63+
'PHPCSDebug' => true,
64+
];
65+
66+
$allStandards = PHP_CodeSniffer\Util\Standards::getInstalledStandards();
67+
$allStandards[] = 'Generic';
68+
69+
$standardsToIgnore = [];
70+
foreach ($allStandards as $standard) {
71+
if (isset($phpcsDevtoolsStandards[$standard]) === true) {
72+
continue;
73+
}
74+
75+
$standardsToIgnore[] = $standard;
76+
}
77+
78+
$standardsToIgnoreString = \implode(',', $standardsToIgnore);
79+
\putenv("PHPCS_IGNORE_TESTS={$standardsToIgnoreString}");
80+
5681
// Clean up.
5782
unset($ds, $phpcsDir, $composerPHPCSPath);
83+
unset($ds, $phpcsDir, $composerPHPCSPath, $allStandards, $standardsToIgnore, $standard, $standardsToIgnoreString);

phpunit.xml.dist

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,4 @@
1313
<directory suffix="UnitTest.php">./PHPCSDebug/Tests/</directory>
1414
</testsuite>
1515
</testsuites>
16-
17-
<php>
18-
<!-- This line prevents issues with PHPCS trying to load sniff files for
19-
standards which we aren't testing.
20-
Ref: https://github.com/squizlabs/PHP_CodeSniffer/pull/1146 -->
21-
<env name="PHPCS_IGNORE_TESTS" value="PHPCompatibility"/>
22-
</php>
2316
</phpunit>
24-

0 commit comments

Comments
 (0)