|
11 | 11 |
|
12 | 12 | use PHP_CodeSniffer\Ruleset; |
13 | 13 | use PHP_CodeSniffer\Tests\ConfigDouble; |
14 | | -use PHPUnit\Framework\TestCase; |
| 14 | +use PHP_CodeSniffer\Tests\Core\Ruleset\AbstractRulesetTestCase; |
15 | 15 |
|
16 | 16 | /** |
17 | 17 | * Test handling of sniffs not following the PHPCS naming conventions in the Ruleset::populateTokenListeners() method. |
18 | 18 | * |
19 | 19 | * @covers \PHP_CodeSniffer\Ruleset::populateTokenListeners |
20 | 20 | */ |
21 | | -final class PopulateTokenListenersNamingConventionsTest extends TestCase |
| 21 | +final class PopulateTokenListenersNamingConventionsTest extends AbstractRulesetTestCase |
22 | 22 | { |
23 | 23 |
|
24 | 24 |
|
25 | 25 | /** |
26 | 26 | * Verify a warning is shown for sniffs not complying with the PHPCS naming conventions. |
27 | 27 | * |
28 | 28 | * Including sniffs which do not comply with the PHPCS naming conventions is soft deprecated since |
29 | | - * PHPCS 3.12.0, hard deprecated since PHPCS 3.13.0 and support will be removed in PHPCS 4.0.0. |
| 29 | + * PHPCS 3.12.0, hard deprecated since PHPCS 3.13.0 and support has been removed in PHPCS 4.0.0. |
30 | 30 | * |
31 | 31 | * @return void |
32 | 32 | */ |
33 | 33 | public function testBrokenNamingConventions() |
34 | 34 | { |
| 35 | + $expectedMessage = 'ERROR: The sniff BrokenNamingConventions\\Sniffs\\MissingCategoryDirSniff does not comply'; |
| 36 | + $expectedMessage .= ' with the PHP_CodeSniffer naming conventions.'.PHP_EOL; |
| 37 | + $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL; |
| 38 | + $expectedMessage .= 'ERROR: The sniff NoNamespaceSniff does not comply with the PHP_CodeSniffer naming conventions.'.PHP_EOL; |
| 39 | + $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL; |
| 40 | + $expectedMessage .= 'ERROR: The sniff Sniffs\PartialNamespaceSniff does not comply with the PHP_CodeSniffer naming conventions.'.PHP_EOL; |
| 41 | + $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL; |
| 42 | + $expectedMessage .= 'ERROR: The sniff BrokenNamingConventions\Sniffs\Category\Sniff does not comply'; |
| 43 | + $expectedMessage .= ' with the PHP_CodeSniffer naming conventions.'.PHP_EOL; |
| 44 | + $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL; |
| 45 | + $expectedMessage .= 'ERROR: The sniff BrokenNamingConventions\Sniffs\Sniffs\CategoryCalledSniffsSniff does not'; |
| 46 | + $expectedMessage .= ' comply with the PHP_CodeSniffer naming conventions.'.PHP_EOL; |
| 47 | + $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL; |
| 48 | + $expectedMessage .= 'ERROR: The sniff BrokenNamingConventions\Sniffs\Category\SubDir\TooDeeplyNestedSniff'; |
| 49 | + $expectedMessage .= ' does not comply with the PHP_CodeSniffer naming conventions.'.PHP_EOL; |
| 50 | + $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL.PHP_EOL; |
| 51 | + |
| 52 | + $this->expectRuntimeExceptionMessage($expectedMessage); |
| 53 | + |
35 | 54 | // Set up the ruleset. |
36 | 55 | $standard = __DIR__.'/PopulateTokenListenersNamingConventionsTest.xml'; |
37 | 56 | $config = new ConfigDouble(["--standard=$standard"]); |
38 | 57 | $ruleset = new Ruleset($config); |
39 | 58 |
|
40 | 59 | // The "Generic.PHP.BacktickOperator" sniff is the only valid sniff. |
41 | 60 | $expectedSniffCodes = [ |
42 | | - '..NoNamespace' => 'NoNamespaceSniff', |
43 | | - '.Sniffs.MissingCategoryDir' => 'BrokenNamingConventions\\Sniffs\\MissingCategoryDirSniff', |
44 | | - '.Sniffs.PartialNamespace' => 'Sniffs\\PartialNamespaceSniff', |
45 | | - 'BrokenNamingConventions.Category.' => 'BrokenNamingConventions\\Sniffs\\Category\\Sniff', |
46 | | - 'BrokenNamingConventions.Sniffs.CategoryCalledSniffs' => 'BrokenNamingConventions\\Sniffs\\Sniffs\\CategoryCalledSniffsSniff', |
47 | | - 'Generic.PHP.BacktickOperator' => 'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\PHP\\BacktickOperatorSniff', |
48 | | - 'Sniffs.SubDir.TooDeeplyNested' => 'BrokenNamingConventions\\Sniffs\\Category\\SubDir\\TooDeeplyNestedSniff', |
| 61 | + 'Generic.PHP.BacktickOperator' => 'PHP_CodeSniffer\\Standards\\Generic\\Sniffs\\PHP\\BacktickOperatorSniff', |
49 | 62 | ]; |
50 | 63 |
|
51 | | - // Sort the value to make the tests stable as different OSes will read directories |
52 | | - // in a different order and the order is not relevant for these tests. Just the values. |
53 | | - $actual = $ruleset->sniffCodes; |
54 | | - ksort($actual); |
55 | | - |
56 | | - $this->assertSame($expectedSniffCodes, $actual, 'Registered sniffs do not match expectation'); |
57 | | - |
58 | | - $expectedMessage = 'DEPRECATED: The sniff BrokenNamingConventions\\Sniffs\\MissingCategoryDirSniff does not comply'; |
59 | | - $expectedMessage .= ' with the PHP_CodeSniffer naming conventions. This will no longer be supported in PHPCS 4.0.'.PHP_EOL; |
60 | | - $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL; |
61 | | - $expectedMessage .= 'DEPRECATED: The sniff NoNamespaceSniff does not comply with the PHP_CodeSniffer naming conventions.'; |
62 | | - $expectedMessage .= ' This will no longer be supported in PHPCS 4.0.'.PHP_EOL; |
63 | | - $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL; |
64 | | - $expectedMessage .= 'DEPRECATED: The sniff Sniffs\\PartialNamespaceSniff does not comply with the PHP_CodeSniffer naming conventions.'; |
65 | | - $expectedMessage .= ' This will no longer be supported in PHPCS 4.0.'.PHP_EOL; |
66 | | - $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL; |
67 | | - $expectedMessage .= 'DEPRECATED: The sniff BrokenNamingConventions\\Sniffs\\Category\\Sniff does not comply'; |
68 | | - $expectedMessage .= ' with the PHP_CodeSniffer naming conventions. This will no longer be supported in PHPCS 4.0.'.PHP_EOL; |
69 | | - $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL; |
70 | | - $expectedMessage .= 'DEPRECATED: The sniff BrokenNamingConventions\\Sniffs\\Sniffs\\CategoryCalledSniffsSniff does not'; |
71 | | - $expectedMessage .= ' comply with the PHP_CodeSniffer naming conventions. This will no longer be supported in PHPCS 4.0.'.PHP_EOL; |
72 | | - $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL; |
73 | | - $expectedMessage .= 'DEPRECATED: The sniff BrokenNamingConventions\\Sniffs\\Category\\SubDir\\TooDeeplyNestedSniff'; |
74 | | - $expectedMessage .= ' does not comply with the PHP_CodeSniffer naming conventions. This will no longer be supported in PHPCS 4.0.'.PHP_EOL; |
75 | | - $expectedMessage .= 'Contact the sniff author to fix the sniff.'.PHP_EOL.PHP_EOL; |
76 | | - |
77 | | - $this->expectOutputString($expectedMessage); |
| 64 | + // This assertion will only take effect for PHPUnit 10+. |
| 65 | + $this->assertSame($expectedSniffCodes, $ruleset->sniffCodes, 'Registered sniffs do not match expectation'); |
78 | 66 |
|
79 | 67 | }//end testBrokenNamingConventions() |
80 | 68 |
|
|
0 commit comments