Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for coding handling STDIN for the sniffs FileName and I18nTextDomainFixer #2512

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions WordPress/Tests/Files/FileNameStdInTest.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="FileNameStdInTest" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
<rule ref="./WordPress/Sniffs/Files/FileNameSniff.php"/>
</ruleset>
23 changes: 23 additions & 0 deletions WordPress/Tests/Files/FileNameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

namespace WordPressCS\WordPress\Tests\Files;

use PHP_CodeSniffer\Files\DummyFile;
use PHP_CodeSniffer\Ruleset;
use PHP_CodeSniffer\Tests\ConfigDouble;
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;

/**
Expand Down Expand Up @@ -172,4 +175,24 @@ public function getErrorList( $testFile = '' ) {
public function getWarningList() {
return array();
}

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

$ruleset = new Ruleset( $config );

$content = '<?php ';
$file = new DummyFile( $content, $ruleset, $config );
$file->process();

$this->assertSame( 0, $file->getErrorCount() );
$this->assertSame( 0, $file->getWarningCount() );
$this->assertCount( 0, $file->getErrors() );
}
}
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() );
}
}
Loading