diff --git a/src/Ruleset.php b/src/Ruleset.php index 7c7b1a4b3c..b99d484fef 100644 --- a/src/Ruleset.php +++ b/src/Ruleset.php @@ -301,10 +301,18 @@ public function explain() } }//end if + if (isset($this->deprecatedSniffs[$sniff]) === true) { + $sniff .= ' *'; + } + $sniffsInStandard[] = $sniff; ++$lastCount; }//end foreach + if (count($this->deprecatedSniffs) > 0) { + echo PHP_EOL.'* Sniffs marked with an asterix are deprecated.'.PHP_EOL; + } + }//end explain() diff --git a/tests/Core/Ruleset/ExplainTest.php b/tests/Core/Ruleset/ExplainTest.php index 73943d3757..fc84f88ac7 100644 --- a/tests/Core/Ruleset/ExplainTest.php +++ b/tests/Core/Ruleset/ExplainTest.php @@ -166,6 +166,48 @@ public function testExplainCustomRuleset() }//end testExplainCustomRuleset() + /** + * Test the output of the "explain" command for a standard containing both deprecated + * and non-deprecated sniffs. + * + * Tests that: + * - Deprecated sniffs are marked with an asterix in the list. + * - A footnote is displayed explaining the asterix. + * - And that the "standard uses # deprecated sniffs" listing is **not** displayed. + * + * @return void + */ + public function testExplainWithDeprecatedSniffs() + { + // Set up the ruleset. + $standard = __DIR__."/ShowSniffDeprecationsTest.xml"; + $config = new ConfigDouble(["--standard=$standard", '-e']); + $ruleset = new Ruleset($config); + + $expected = PHP_EOL; + $expected .= 'The SniffDeprecationTest standard contains 9 sniffs'.PHP_EOL.PHP_EOL; + + $expected .= 'Fixtures (9 sniffs)'.PHP_EOL; + $expected .= '-------------------'.PHP_EOL; + $expected .= ' Fixtures.Deprecated.WithLongReplacement *'.PHP_EOL; + $expected .= ' Fixtures.Deprecated.WithoutReplacement *'.PHP_EOL; + $expected .= ' Fixtures.Deprecated.WithReplacement *'.PHP_EOL; + $expected .= ' Fixtures.Deprecated.WithReplacementContainingLinuxNewlines *'.PHP_EOL; + $expected .= ' Fixtures.Deprecated.WithReplacementContainingNewlines *'.PHP_EOL; + $expected .= ' Fixtures.SetProperty.AllowedAsDeclared'.PHP_EOL; + $expected .= ' Fixtures.SetProperty.AllowedViaMagicMethod'.PHP_EOL; + $expected .= ' Fixtures.SetProperty.AllowedViaStdClass'.PHP_EOL; + $expected .= ' Fixtures.SetProperty.NotAllowedViaAttribute'.PHP_EOL.PHP_EOL; + + $expected .= '* Sniffs marked with an asterix are deprecated.'.PHP_EOL; + + $this->expectOutputString($expected); + + $ruleset->explain(); + + }//end testExplainWithDeprecatedSniffs() + + /** * Test that each standard passed on the command-line is explained separately. *