|
9 | 9 |
|
10 | 10 | namespace WordPressCS\WordPress\Tests\Utils; |
11 | 11 |
|
| 12 | +use PHP_CodeSniffer\Files\DummyFile; |
| 13 | +use PHP_CodeSniffer\Ruleset; |
12 | 14 | use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest; |
13 | 15 | use PHPCSUtils\BackCompat\Helper; |
| 16 | +use PHPCSUtils\TestUtils\ConfigDouble; |
14 | 17 |
|
15 | 18 | /** |
16 | 19 | * Unit test class for the I18nTextDomainFixer sniff. |
@@ -200,4 +203,32 @@ public function getWarningList( $testFile = '' ) { |
200 | 203 | return array(); |
201 | 204 | } |
202 | 205 | } |
| 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 | + } |
203 | 234 | } |
0 commit comments