Skip to content

Commit c84a086

Browse files
authored
Merge pull request #2512 from rodrigoprimo/test-stdin
Add tests for code handling STDIN for the sniffs FileName and I18nTextDomainFixer
2 parents 8189aff + 632b6ae commit c84a086

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

WordPress/Tests/Files/FileNameUnitTest.php

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

1010
namespace WordPressCS\WordPress\Tests\Files;
1111

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

1418
/**
1519
* Unit test class for the FileName sniff.
@@ -172,4 +176,26 @@ public function getErrorList( $testFile = '' ) {
172176
public function getWarningList() {
173177
return array();
174178
}
179+
180+
/**
181+
* Test the sniff bails early when handling STDIN.
182+
*
183+
* @return void
184+
*/
185+
public function testStdIn() {
186+
$config = new ConfigDouble();
187+
Helper::setConfigData( 'installed_paths', dirname( dirname( __DIR__ ) ), true, $config );
188+
$config->standards = array( 'WordPress' );
189+
$config->sniffs = array( 'WordPress.Files.FileName' );
190+
191+
$ruleset = new Ruleset( $config );
192+
193+
$content = '<?php ';
194+
$file = new DummyFile( $content, $ruleset, $config );
195+
$file->process();
196+
197+
$this->assertSame( 0, $file->getErrorCount() );
198+
$this->assertSame( 0, $file->getWarningCount() );
199+
$this->assertCount( 0, $file->getErrors() );
200+
}
175201
}

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)