Skip to content

Commit

Permalink
Ruleset::populateTokenListeners(): add tests (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl authored Dec 19, 2024
1 parent e8edff7 commit 46b9a59
Show file tree
Hide file tree
Showing 9 changed files with 660 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tests/Core/Ruleset/ExplainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ public function testExplainWithDeprecatedSniffs()
$ruleset = new Ruleset($config);

$expected = PHP_EOL;
$expected .= 'The ShowSniffDeprecationsTest standard contains 10 sniffs'.PHP_EOL.PHP_EOL;
$expected .= 'The ShowSniffDeprecationsTest standard contains 11 sniffs'.PHP_EOL.PHP_EOL;

$expected .= 'TestStandard (10 sniffs)'.PHP_EOL;
$expected .= 'TestStandard (11 sniffs)'.PHP_EOL;
$expected .= '------------------------'.PHP_EOL;
$expected .= ' TestStandard.Deprecated.WithLongReplacement *'.PHP_EOL;
$expected .= ' TestStandard.Deprecated.WithoutReplacement *'.PHP_EOL;
Expand All @@ -198,7 +198,8 @@ public function testExplainWithDeprecatedSniffs()
$expected .= ' TestStandard.SetProperty.AllowedViaMagicMethod'.PHP_EOL;
$expected .= ' TestStandard.SetProperty.AllowedViaStdClass'.PHP_EOL;
$expected .= ' TestStandard.SetProperty.NotAllowedViaAttribute'.PHP_EOL;
$expected .= ' TestStandard.SetProperty.PropertyTypeHandling'.PHP_EOL.PHP_EOL;
$expected .= ' TestStandard.SetProperty.PropertyTypeHandling'.PHP_EOL;
$expected .= ' TestStandard.ValidSniffs.RegisterEmptyArray'.PHP_EOL.PHP_EOL;

$expected .= '* Sniffs marked with an asterix are deprecated.'.PHP_EOL;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Test fixture.
*
* @see \PHP_CodeSniffer\Tests\Core\Ruleset\PopulateTokenListenersTest
*/

namespace Fixtures\TestStandard\Sniffs\InvalidSniffs;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

class RegisterNoArraySniff implements Sniff
{

public function register()
{
return false;
}

public function process(File $phpcsFile, $stackPtr)
{
// Do something.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Test fixture.
*
* @see \PHP_CodeSniffer\Tests\Core\Ruleset\PopulateTokenListenersTest
*/

namespace Fixtures\TestStandard\Sniffs\ValidSniffs;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

class RegisterEmptyArraySniff implements Sniff
{

public function register()
{
return [];
}

public function process(File $phpcsFile, $stackPtr)
{
// Do something.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PopulateTokenListenersTest" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">

<config name="installed_paths" value="./tests/Core/Ruleset/Fixtures/TestStandard/"/>

<rule ref="TestStandard.InvalidSniffs.RegisterNoArray"/>

</ruleset>
Loading

0 comments on commit 46b9a59

Please sign in to comment.