Skip to content

Commit c682491

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 7b6138f commit c682491

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="I18nTextDomainFixerStdInTest" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
3+
<rule ref="./WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php"/>
4+
</ruleset>

WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
namespace WordPressCS\WordPress\Tests\Utils;
1111

12+
use PHP_CodeSniffer\Files\DummyFile;
13+
use PHP_CodeSniffer\Ruleset;
14+
use PHP_CodeSniffer\Tests\ConfigDouble;
1215
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
1316
use PHPCSUtils\BackCompat\Helper;
1417

@@ -197,4 +200,30 @@ public function getWarningList( $testFile = '' ) {
197200
return array();
198201
}
199202
}
203+
204+
/**
205+
* Test the sniff bails early when handling a plugin header passed via STDIN.
206+
*
207+
* @return void
208+
*/
209+
public function testStdIn() {
210+
$config = new ConfigDouble();
211+
$config->standards = array( __DIR__ . '/I18nTextDomainFixerStdInTest.xml' );
212+
213+
$ruleset = new Ruleset( $config );
214+
215+
$content = '<?php // phpcs:set WordPress.Utils.I18nTextDomainFixer new_text_domain test-std-in
216+
/**
217+
* Plugin Name: Missing text domain, docblock format.
218+
* Plugin URI: https://www.bigvoodoo.com/
219+
* Description: Sniff triggers a missing text domain error for a normal file, but not for STDIN.
220+
*/';
221+
222+
$file = new DummyFile( $content, $ruleset, $config );
223+
$file->process();
224+
225+
$this->assertSame( 0, $file->getErrorCount() );
226+
$this->assertSame( 0, $file->getWarningCount() );
227+
$this->assertCount( 0, $file->getErrors() );
228+
}
200229
}

0 commit comments

Comments
 (0)