Skip to content

Commit 632b6ae

Browse files
committed
I18nTextDomainFixer: add a test for code handling STDIN
The sniff bails early when handling a plugin header passed via STDIN. This commit adds a test to cover that part of the sniff code.
1 parent 72e279d commit 632b6ae

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
namespace WordPressCS\WordPress\Tests\Utils;
1111

12+
use PHP_CodeSniffer\Files\DummyFile;
13+
use PHP_CodeSniffer\Ruleset;
1214
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
1315
use PHPCSUtils\BackCompat\Helper;
16+
use PHPCSUtils\TestUtils\ConfigDouble;
1417

1518
/**
1619
* Unit test class for the I18nTextDomainFixer sniff.
@@ -200,4 +203,32 @@ public function getWarningList( $testFile = '' ) {
200203
return array();
201204
}
202205
}
206+
207+
/**
208+
* Test the sniff bails early when handling a plugin header passed via STDIN.
209+
*
210+
* @return void
211+
*/
212+
public function testStdIn() {
213+
$config = new ConfigDouble();
214+
Helper::setConfigData( 'installed_paths', dirname( dirname( __DIR__ ) ), true, $config );
215+
$config->standards = array( 'WordPress' );
216+
$config->sniffs = array( 'WordPress.Utils.I18nTextDomainFixer' );
217+
218+
$ruleset = new Ruleset( $config );
219+
220+
$content = '<?php // phpcs:set WordPress.Utils.I18nTextDomainFixer new_text_domain test-std-in
221+
/**
222+
* Plugin Name: Missing text domain, docblock format.
223+
* Plugin URI: https://www.bigvoodoo.com/
224+
* Description: Sniff triggers a missing text domain error for a normal file, but not for STDIN.
225+
*/';
226+
227+
$file = new DummyFile( $content, $ruleset, $config );
228+
$file->process();
229+
230+
$this->assertSame( 0, $file->getErrorCount() );
231+
$this->assertSame( 0, $file->getWarningCount() );
232+
$this->assertCount( 0, $file->getErrors() );
233+
}
203234
}

0 commit comments

Comments
 (0)