Skip to content
Merged
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
26 changes: 26 additions & 0 deletions WordPress/Tests/Files/FileNameUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

namespace WordPressCS\WordPress\Tests\Files;

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

/**
* Unit test class for the FileName sniff.
Expand Down Expand Up @@ -172,4 +176,26 @@ 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();
Helper::setConfigData( 'installed_paths', dirname( dirname( __DIR__ ) ), true, $config );
$config->standards = array( 'WordPress' );
$config->sniffs = array( 'WordPress.Files.FileName' );

$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() );
}
}
31 changes: 31 additions & 0 deletions WordPress/Tests/Utils/I18nTextDomainFixerUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

namespace WordPressCS\WordPress\Tests\Utils;

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

/**
* Unit test class for the I18nTextDomainFixer sniff.
Expand Down Expand Up @@ -200,4 +203,32 @@ 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();
Helper::setConfigData( 'installed_paths', dirname( dirname( __DIR__ ) ), true, $config );
$config->standards = array( 'WordPress' );
$config->sniffs = array( 'WordPress.Utils.I18nTextDomainFixer' );

$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