diff --git a/PHPCSDebug/Tests/Debug/TokenListCssTest.php b/PHPCSDebug/Tests/Debug/TokenListCssTest.php index 456fec8..338a918 100644 --- a/PHPCSDebug/Tests/Debug/TokenListCssTest.php +++ b/PHPCSDebug/Tests/Debug/TokenListCssTest.php @@ -10,6 +10,7 @@ namespace PHPCSDebug\Tests\Debug; +use PHP_CodeSniffer\Util\Common; use PHPCSUtils\TestUtils\UtilityMethodTestCase; /** @@ -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(); } diff --git a/PHPCSDebug/Tests/Debug/TokenListJsTest.php b/PHPCSDebug/Tests/Debug/TokenListJsTest.php index d6481c5..6332715 100644 --- a/PHPCSDebug/Tests/Debug/TokenListJsTest.php +++ b/PHPCSDebug/Tests/Debug/TokenListJsTest.php @@ -10,6 +10,7 @@ namespace PHPCSDebug\Tests\Debug; +use PHP_CodeSniffer\Util\Common; use PHPCSUtils\TestUtils\UtilityMethodTestCase; /** @@ -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(); } diff --git a/PHPCSDebug/Tests/Debug/TokenListUnitTest.php b/PHPCSDebug/Tests/Debug/TokenListUnitTest.php index 2817063..ce948ec 100644 --- a/PHPCSDebug/Tests/Debug/TokenListUnitTest.php +++ b/PHPCSDebug/Tests/Debug/TokenListUnitTest.php @@ -10,6 +10,7 @@ namespace PHPCSDebug\Tests\Debug; +use PHP_CodeSniffer\Util\Common; use PHPCSUtils\TestUtils\UtilityMethodTestCase; /** @@ -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(); } diff --git a/phpunit-bootstrap.php b/phpunit-bootstrap.php index 41ef84b..96e4cdf 100644 --- a/phpunit-bootstrap.php +++ b/phpunit-bootstrap.php @@ -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';