Skip to content

Commit 9aeec04

Browse files
committed
Tests: fix testStdIn() methods to work with PHPCS 4.x
PHPCS 4.x removed special test-specific code from the Ruleset class that handled `Config::$sniffs` restrictions differently when `PHP_CODESNIFFER_IN_TESTS` was defined (see PHPCSStandards/PHP_CodeSniffer/ 996). This caused `testStdIn()` tests that used `$config->standards = array('WordPress')` to attempt loading the entire WordPress standard with all dependencies, resulting in errors about missing standards. The fix uses minimal ruleset XML files that only include the specific sniff being tested making the test pass with both PHPCS 3.x and 4.x.
1 parent d41b6eb commit 9aeec04

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="FileNameStdInTest" xsi:noNamespaceSchemaLocation="https://schema.phpcodesniffer.com/phpcs.xsd">
3+
<description>Ruleset for testing FileName with STDIN.</description>
4+
5+
<rule ref="WordPress.Files.FileName"/>
6+
7+
</ruleset>

WordPress/Tests/Files/FileNameUnitTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ public function getWarningList() {
185185
public function testStdIn() {
186186
$config = new ConfigDouble();
187187
Helper::setConfigData( 'installed_paths', dirname( dirname( __DIR__ ) ), true, $config );
188-
$config->standards = array( 'WordPress' );
189-
$config->sniffs = array( 'WordPress.Files.FileName' );
188+
$config->standards = array( __DIR__ . '/FileNameStdInTest.xml' );
190189

191190
$ruleset = new Ruleset( $config );
192191

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="I18nTextDomainFixerStdInTest" xsi:noNamespaceSchemaLocation="https://schema.phpcodesniffer.com/phpcs.xsd">
3+
<description>Ruleset for testing I18nTextDomainFixer with STDIN.</description>
4+
5+
<rule ref="WordPress.Utils.I18nTextDomainFixer"/>
6+
7+
</ruleset>

WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,7 @@ public function getWarningList( $testFile = '' ) {
214214
public function testStdIn() {
215215
$config = new ConfigDouble();
216216
Helper::setConfigData( 'installed_paths', dirname( dirname( __DIR__ ) ), true, $config );
217-
$config->standards = array( 'WordPress' );
218-
$config->sniffs = array( 'WordPress.Utils.I18nTextDomainFixer' );
217+
$config->standards = array( __DIR__ . '/I18nTextDomainFixerStdInTest.xml' );
219218

220219
$ruleset = new Ruleset( $config );
221220

0 commit comments

Comments
 (0)