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

RulesetTest: fix compatibility with Windows #503

Merged
merged 1 commit into from
Jul 21, 2020
Merged
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
18 changes: 14 additions & 4 deletions tests/RulesetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class RulesetTest {
*/
private $ruleset;

/**
* Path to the PHPCS executable.
*
* @var string
*/
private $phpcs_bin = 'phpcs';

/**
* String returned by PHP_CodeSniffer report for an Error.
*/
Expand All @@ -82,17 +89,20 @@ public function __construct( $ruleset, $expected = [] ) {
$this->ruleset = $ruleset;
$this->expected = $expected;

// Travis support.
if ( false === getenv( 'PHPCS_BIN' ) ) {
// Travis and Windows support.
$phpcs_bin = getenv( 'PHPCS_BIN' );
if ( false === $phpcs_bin ) {
// phpcs:ignore
putenv( 'PHPCS_BIN=phpcs' );
} else {
$this->phpcs_bin = realpath( $phpcs_bin );
}

$output = $this->collect_phpcs_result();

if ( ! is_object( $output ) || empty( $output ) ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
printf( 'The PHPCS command checking the ruleset haven\'t returned any issues. Bailing ...' . PHP_EOL );
printf( 'The PHPCS command checking the ruleset hasn\'t returned any issues. Bailing ...' . PHP_EOL );
exit( 1 ); // Die early, if we don't have any output.
}

Expand Down Expand Up @@ -128,7 +138,7 @@ private function run() {
* @return array Returns an associative array with keys of `totals` and `files`.
*/
private function collect_phpcs_result() {
$shell = sprintf( '$PHPCS_BIN --severity=1 --standard=%1$s --report=json ./%1$s/ruleset-test.inc', $this->ruleset );
$shell = sprintf( '%1$s --severity=1 --standard=%2$s --report=json ./%2$s/ruleset-test.inc', $this->phpcs_bin, $this->ruleset );
// phpcs:ignore
$output = shell_exec( $shell );

Expand Down