From c6824919326da9c7e1eac98575975e28120d5d67 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Fri, 29 Nov 2024 16:50:23 -0300 Subject: [PATCH] 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. --- .../Utils/I18nTextDomainFixerStdInTest.xml | 4 +++ .../Utils/I18nTextDomainFixerUnitTest.php | 29 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 WordPress/Tests/Utils/I18nTextDomainFixerStdInTest.xml diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerStdInTest.xml b/WordPress/Tests/Utils/I18nTextDomainFixerStdInTest.xml new file mode 100644 index 0000000000..f4b5513a46 --- /dev/null +++ b/WordPress/Tests/Utils/I18nTextDomainFixerStdInTest.xml @@ -0,0 +1,4 @@ + + + + diff --git a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php index 8da63235c1..078ffffe7f 100644 --- a/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php +++ b/WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php @@ -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; @@ -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 = 'process(); + + $this->assertSame( 0, $file->getErrorCount() ); + $this->assertSame( 0, $file->getWarningCount() ); + $this->assertCount( 0, $file->getErrors() ); + } }