Skip to content

Commit

Permalink
Merge pull request #137 from PHPCSStandards/phpcsdebug/fix-tests
Browse files Browse the repository at this point in the history
PHPCSDebug: fix tests
  • Loading branch information
jrfnl committed Mar 4, 2024
2 parents aa6f5d6 + 8c77b05 commit fb626bf
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
12 changes: 12 additions & 0 deletions PHPCSDebug/Tests/Debug/TokenListCssTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCSDebug\Tests\Debug;

use PHP_CodeSniffer\Util\Common;
use PHPCSUtils\TestUtils\UtilityMethodTestCase;

/**
Expand Down Expand Up @@ -115,6 +116,17 @@ public function testOutput()
$this->expectOutputString($expected);
$this->setOutputCallback([$this, 'normalizeLineEndings']);

if (empty($this->ruleset->tokenListeners)) {
// PHPCSUtils 1.0.9+.
$sniffFile = \dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'Sniffs';
$sniffFile .= \DIRECTORY_SEPARATOR . 'Debug' . \DIRECTORY_SEPARATOR . 'TokenListSniff.php';
$sniffClassName = Common::cleanSniffClass('PHPCSDebug\\Sniffs\\Debug\\TokenListSniff');

$restrictions = [\strtolower($sniffClassName) => true];
self::$phpcsFile->ruleset->registerSniffs([$sniffFile], $restrictions, []);
self::$phpcsFile->ruleset->populateTokenListeners();
}

self::$phpcsFile->process();
}

Expand Down
12 changes: 12 additions & 0 deletions PHPCSDebug/Tests/Debug/TokenListJsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCSDebug\Tests\Debug;

use PHP_CodeSniffer\Util\Common;
use PHPCSUtils\TestUtils\UtilityMethodTestCase;

/**
Expand Down Expand Up @@ -135,6 +136,17 @@ public function testOutput()
$this->expectOutputString($expected);
$this->setOutputCallback([$this, 'normalizeLineEndings']);

if (empty($this->ruleset->tokenListeners)) {
// PHPCSUtils 1.0.9+.
$sniffFile = \dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'Sniffs';
$sniffFile .= \DIRECTORY_SEPARATOR . 'Debug' . \DIRECTORY_SEPARATOR . 'TokenListSniff.php';
$sniffClassName = Common::cleanSniffClass('PHPCSDebug\\Sniffs\\Debug\\TokenListSniff');

$restrictions = [\strtolower($sniffClassName) => true];
self::$phpcsFile->ruleset->registerSniffs([$sniffFile], $restrictions, []);
self::$phpcsFile->ruleset->populateTokenListeners();
}

self::$phpcsFile->process();
}

Expand Down
12 changes: 12 additions & 0 deletions PHPCSDebug/Tests/Debug/TokenListUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace PHPCSDebug\Tests\Debug;

use PHP_CodeSniffer\Util\Common;
use PHPCSUtils\TestUtils\UtilityMethodTestCase;

/**
Expand Down Expand Up @@ -108,6 +109,17 @@ public function testOutput()
$this->expectOutputString($expected);
$this->setOutputCallback([$this, 'normalizeLineEndings']);

if (empty($this->ruleset->tokenListeners)) {
// PHPCSUtils 1.0.9+.
$sniffFile = \dirname(\dirname(__DIR__)) . \DIRECTORY_SEPARATOR . 'Sniffs';
$sniffFile .= \DIRECTORY_SEPARATOR . 'Debug' . \DIRECTORY_SEPARATOR . 'TokenListSniff.php';
$sniffClassName = Common::cleanSniffClass('PHPCSDebug\\Sniffs\\Debug\\TokenListSniff');

$restrictions = [\strtolower($sniffClassName) => true];
self::$phpcsFile->ruleset->registerSniffs([$sniffFile], $restrictions, []);
self::$phpcsFile->ruleset->populateTokenListeners();
}

self::$phpcsFile->process();
}

Expand Down
5 changes: 5 additions & 0 deletions phpunit-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
die(1);
}

$installedStandards = \PHP_CodeSniffer\Util\Standards::getInstalledStandardDetails();
foreach ($installedStandards as $details) {
\PHP_CodeSniffer\Autoload::addSearchPath($details['path'], $details['namespace']);
}

// Try and load the PHPCSUtils autoloader.
if ($phpcsUtilsDir !== false && \file_exists($phpcsUtilsDir . $ds . 'phpcsutils-autoload.php')) {
require_once $phpcsUtilsDir . $ds . 'phpcsutils-autoload.php';
Expand Down

0 comments on commit fb626bf

Please sign in to comment.