Skip to content

Commit 0a364dc

Browse files
committed
Ruleset::processRule(): add test for handling of invalid <type> directives
1 parent e66802a commit 0a364dc

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Test handling of invalid type elements.
4+
*
5+
* @author Juliette Reinders Folmer <[email protected]>
6+
* @copyright 2024 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 PHP_CodeSniffer\Tests\Core\Ruleset\AbstractRulesetTestCase;
15+
16+
/**
17+
* Test handling of invalid type elements.
18+
*
19+
* @covers \PHP_CodeSniffer\Ruleset::processRule
20+
*/
21+
final class ProcessRuleInvalidTypeTest extends AbstractRulesetTestCase
22+
{
23+
24+
25+
/**
26+
* Test displaying an informative error message when an invalid type is given.
27+
*
28+
* @return void
29+
*/
30+
public function testInvalidTypeHandling()
31+
{
32+
$standard = __DIR__.'/ProcessRuleInvalidTypeTest.xml';
33+
$config = new ConfigDouble(["--standard=$standard"]);
34+
35+
$message = 'Message type "notice" is invalid; must be "error" or "warning"';
36+
$this->expectRuntimeExceptionMessage($message);
37+
38+
new Ruleset($config);
39+
40+
}//end testInvalidTypeHandling()
41+
42+
43+
}//end class
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="ProcessRuleInvalidTypeTest" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/PHPCSStandards/PHP_CodeSniffer/master/phpcs.xsd">
3+
4+
<rule ref="Generic.Files.ByteOrderMark">
5+
<!-- Invalid type will throw an error. -->
6+
<type>notice</type>
7+
</rule>
8+
9+
</ruleset>

0 commit comments

Comments
 (0)