Skip to content

Commit

Permalink
I18nTextDomainFixer: add a test for code handling STDIN
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rodrigoprimo committed Nov 29, 2024
1 parent 7b6138f commit c682491
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions WordPress/Tests/Utils/I18nTextDomainFixerStdInTest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="I18nTextDomainFixerStdInTest" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
<rule ref="./WordPress/Sniffs/Utils/I18nTextDomainFixerSniff.php"/>
</ruleset>
29 changes: 29 additions & 0 deletions WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace WordPressCS\WordPress\Tests\Utils;

use PHP_CodeSniffer\Files\DummyFile;
use PHP_CodeSniffer\Ruleset;
use PHP_CodeSniffer\Tests\ConfigDouble;
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
use PHPCSUtils\BackCompat\Helper;

Expand Down Expand Up @@ -197,4 +200,30 @@ public function getWarningList( $testFile = '' ) {
return array();
}
}

/**
* Test the sniff bails early when handling a plugin header passed via STDIN.
*
* @return void
*/
public function testStdIn() {
$config = new ConfigDouble();
$config->standards = array( __DIR__ . '/I18nTextDomainFixerStdInTest.xml' );

$ruleset = new Ruleset( $config );

$content = '<?php // phpcs:set WordPress.Utils.I18nTextDomainFixer new_text_domain test-std-in
/**
* Plugin Name: Missing text domain, docblock format.
* Plugin URI: https://www.bigvoodoo.com/
* Description: Sniff triggers a missing text domain error for a normal file, but not for STDIN.
*/';

$file = new DummyFile( $content, $ruleset, $config );
$file->process();

$this->assertSame( 0, $file->getErrorCount() );
$this->assertSame( 0, $file->getWarningCount() );
$this->assertCount( 0, $file->getErrors() );
}
}

0 comments on commit c682491

Please sign in to comment.