|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests deprecation of support for sniffs not implementing the PHPCS `Sniff` interface. |
| 4 | + * |
| 5 | + * @author Juliette Reinders Folmer <[email protected]> |
| 6 | + * @copyright 2025 PHPCSStandards and contributors |
| 7 | + * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence |
| 8 | + */ |
| 9 | + |
| 10 | +namespace PHP_CodeSniffer\Tests\Core\Ruleset; |
| 11 | + |
| 12 | +use PHP_CodeSniffer\Ruleset; |
| 13 | +use PHP_CodeSniffer\Tests\ConfigDouble; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +/** |
| 17 | + * Tests deprecation of support for sniffs not implementing the PHPCS `Sniff` interface. |
| 18 | + * |
| 19 | + * @covers \PHP_CodeSniffer\Ruleset::registerSniffs |
| 20 | + */ |
| 21 | +final class RegisterSniffsMissingInterfaceTest extends TestCase |
| 22 | +{ |
| 23 | + |
| 24 | + |
| 25 | + /** |
| 26 | + * Test that no deprecation is shown when sniffs implement the `PHP_CodeSniffer\Sniffs\Sniff` interface. |
| 27 | + * |
| 28 | + * @return void |
| 29 | + */ |
| 30 | + public function testNoNoticesForSniffsImplementingInterface() |
| 31 | + { |
| 32 | + // Set up the ruleset. |
| 33 | + $standard = __DIR__.'/RegisterSniffsMissingInterfaceValidTest.xml'; |
| 34 | + $config = new ConfigDouble(["--standard=$standard"]); |
| 35 | + |
| 36 | + $this->expectOutputString(''); |
| 37 | + |
| 38 | + new Ruleset($config); |
| 39 | + |
| 40 | + }//end testNoNoticesForSniffsImplementingInterface() |
| 41 | + |
| 42 | + |
| 43 | + /** |
| 44 | + * Test that a deprecation notice is shown if a sniff doesn't implement the Sniff interface. |
| 45 | + * |
| 46 | + * @return void |
| 47 | + */ |
| 48 | + public function testDeprecationNoticeWhenSniffDoesntImplementInterface() |
| 49 | + { |
| 50 | + // Set up the ruleset. |
| 51 | + $standard = __DIR__.'/RegisterSniffsMissingInterfaceInvalidTest.xml'; |
| 52 | + $config = new ConfigDouble(["--standard=$standard"]); |
| 53 | + |
| 54 | + $expected = 'DEPRECATED: All sniffs must implement the PHP_CodeSniffer\\Sniffs\\Sniff interface.'.PHP_EOL; |
| 55 | + $expected .= 'Interface not implemented for sniff Fixtures\\TestStandard\\Sniffs\\MissingInterface\\InvalidImplementsWithoutImplementSniff.'.PHP_EOL; |
| 56 | + $expected .= 'Contact the sniff author to fix the sniff.'.PHP_EOL.PHP_EOL; |
| 57 | + |
| 58 | + $this->expectOutputString($expected); |
| 59 | + |
| 60 | + new Ruleset($config); |
| 61 | + |
| 62 | + }//end testDeprecationNoticeWhenSniffDoesntImplementInterface() |
| 63 | + |
| 64 | + |
| 65 | +}//end class |
0 commit comments