From ab8a43c7d81ad85de851bc0035b51c1de315e557 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 18 Nov 2024 06:27:19 +0100 Subject: [PATCH] Ruleset::processRule(): add test for handling of invalid `` directives --- .../Ruleset/ProcessRuleInvalidTypeTest.php | 43 +++++++++++++++++++ .../Ruleset/ProcessRuleInvalidTypeTest.xml | 9 ++++ 2 files changed, 52 insertions(+) create mode 100644 tests/Core/Ruleset/ProcessRuleInvalidTypeTest.php create mode 100644 tests/Core/Ruleset/ProcessRuleInvalidTypeTest.xml diff --git a/tests/Core/Ruleset/ProcessRuleInvalidTypeTest.php b/tests/Core/Ruleset/ProcessRuleInvalidTypeTest.php new file mode 100644 index 0000000000..08a2e6b822 --- /dev/null +++ b/tests/Core/Ruleset/ProcessRuleInvalidTypeTest.php @@ -0,0 +1,43 @@ + + * @copyright 2024 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; + +/** + * Test handling of invalid type elements. + * + * @covers \PHP_CodeSniffer\Ruleset::processRule + */ +final class ProcessRuleInvalidTypeTest extends AbstractRulesetTestCase +{ + + + /** + * Test displaying an informative error message when an invalid type is given. + * + * @return void + */ + public function testInvalidTypeHandling() + { + $standard = __DIR__.'/ProcessRuleInvalidTypeTest.xml'; + $config = new ConfigDouble(["--standard=$standard"]); + + $message = 'Message type "notice" is invalid; must be "error" or "warning"'; + $this->expectRuntimeExceptionMessage($message); + + new Ruleset($config); + + }//end testInvalidTypeHandling() + + +}//end class diff --git a/tests/Core/Ruleset/ProcessRuleInvalidTypeTest.xml b/tests/Core/Ruleset/ProcessRuleInvalidTypeTest.xml new file mode 100644 index 0000000000..63c2aaf3c8 --- /dev/null +++ b/tests/Core/Ruleset/ProcessRuleInvalidTypeTest.xml @@ -0,0 +1,9 @@ + + + + + + notice + + +