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