-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathRegisterSniffsRejectsInvalidSniffTest.php
80 lines (67 loc) · 2.71 KB
/
RegisterSniffsRejectsInvalidSniffTest.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Tests that invalid sniffs will be rejected with an informative error message.
*
* @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 PHP_CodeSniffer\Tests\Core\Ruleset\AbstractRulesetTestCase;
/**
* Tests that invalid sniffs will be rejected with an informative error message.
*
* @covers \PHP_CodeSniffer\Ruleset::registerSniffs
*/
final class RegisterSniffsRejectsInvalidSniffTest extends AbstractRulesetTestCase
{
/**
* Verify that an error is thrown if an invalid sniff class is loaded.
*
* @param string $standard The standard to use for the test.
* @param string $methodName The name of the missing method.
*
* @dataProvider dataExceptionIsThrownOnMissingInterfaceMethod
*
* @return void
*/
public function testExceptionIsThrownOnMissingInterfaceMethod($standard, $methodName)
{
// Set up the ruleset.
$standard = __DIR__.'/'.$standard;
$config = new ConfigDouble(["--standard=$standard"]);
$regex = "`(^|\R)ERROR: Sniff class \S+Sniff is missing required method $methodName\(\)\.\R`";
$this->expectRuntimeExceptionRegex($regex);
new Ruleset($config);
}//end testExceptionIsThrownOnMissingInterfaceMethod()
/**
* Data provider.
*
* @see testExceptionIsThrownOnMissingInterfaceMethod()
*
* @return array<string, array<string, string>>
*/
public static function dataExceptionIsThrownOnMissingInterfaceMethod()
{
return [
'Missing register() method' => [
'standard' => 'RegisterSniffsRejectsInvalidSniffNoImplementsNoRegisterTest.xml',
'methodName' => 'register',
],
'Missing process() method' => [
'standard' => 'RegisterSniffsRejectsInvalidSniffNoImplementsNoProcessTest.xml',
'methodName' => 'process',
],
'Missing both, checking register() method' => [
'standard' => 'RegisterSniffsRejectsInvalidSniffNoImplementsNoRegisterOrProcessTest.xml',
'methodName' => 'register',
],
'Missing both, checking process() method' => [
'standard' => 'RegisterSniffsRejectsInvalidSniffNoImplementsNoRegisterOrProcessTest.xml',
'methodName' => 'process',
],
];
}//end dataExceptionIsThrownOnMissingInterfaceMethod()
}//end class