Skip to content

Commit 46b9a59

Browse files
authored
Ruleset::populateTokenListeners(): add tests (#757)
1 parent e8edff7 commit 46b9a59

9 files changed

+660
-4
lines changed

tests/Core/Ruleset/ExplainTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ public function testExplainWithDeprecatedSniffs()
185185
$ruleset = new Ruleset($config);
186186

187187
$expected = PHP_EOL;
188-
$expected .= 'The ShowSniffDeprecationsTest standard contains 10 sniffs'.PHP_EOL.PHP_EOL;
188+
$expected .= 'The ShowSniffDeprecationsTest standard contains 11 sniffs'.PHP_EOL.PHP_EOL;
189189

190-
$expected .= 'TestStandard (10 sniffs)'.PHP_EOL;
190+
$expected .= 'TestStandard (11 sniffs)'.PHP_EOL;
191191
$expected .= '------------------------'.PHP_EOL;
192192
$expected .= ' TestStandard.Deprecated.WithLongReplacement *'.PHP_EOL;
193193
$expected .= ' TestStandard.Deprecated.WithoutReplacement *'.PHP_EOL;
@@ -198,7 +198,8 @@ public function testExplainWithDeprecatedSniffs()
198198
$expected .= ' TestStandard.SetProperty.AllowedViaMagicMethod'.PHP_EOL;
199199
$expected .= ' TestStandard.SetProperty.AllowedViaStdClass'.PHP_EOL;
200200
$expected .= ' TestStandard.SetProperty.NotAllowedViaAttribute'.PHP_EOL;
201-
$expected .= ' TestStandard.SetProperty.PropertyTypeHandling'.PHP_EOL.PHP_EOL;
201+
$expected .= ' TestStandard.SetProperty.PropertyTypeHandling'.PHP_EOL;
202+
$expected .= ' TestStandard.ValidSniffs.RegisterEmptyArray'.PHP_EOL.PHP_EOL;
202203

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Test fixture.
4+
*
5+
* @see \PHP_CodeSniffer\Tests\Core\Ruleset\PopulateTokenListenersTest
6+
*/
7+
8+
namespace Fixtures\TestStandard\Sniffs\InvalidSniffs;
9+
10+
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
13+
class RegisterNoArraySniff implements Sniff
14+
{
15+
16+
public function register()
17+
{
18+
return false;
19+
}
20+
21+
public function process(File $phpcsFile, $stackPtr)
22+
{
23+
// Do something.
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* Test fixture.
4+
*
5+
* @see \PHP_CodeSniffer\Tests\Core\Ruleset\PopulateTokenListenersTest
6+
*/
7+
8+
namespace Fixtures\TestStandard\Sniffs\ValidSniffs;
9+
10+
use PHP_CodeSniffer\Files\File;
11+
use PHP_CodeSniffer\Sniffs\Sniff;
12+
13+
class RegisterEmptyArraySniff implements Sniff
14+
{
15+
16+
public function register()
17+
{
18+
return [];
19+
}
20+
21+
public function process(File $phpcsFile, $stackPtr)
22+
{
23+
// Do something.
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PopulateTokenListenersTest" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
3+
4+
<config name="installed_paths" value="./tests/Core/Ruleset/Fixtures/TestStandard/"/>
5+
6+
<rule ref="TestStandard.InvalidSniffs.RegisterNoArray"/>
7+
8+
</ruleset>

0 commit comments

Comments
 (0)