From 3b2f88fc5de630760f6c0db926dd797ebf8caa77 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Fri, 22 Dec 2023 11:38:04 -0300 Subject: [PATCH] Generic/NoSilencedErrors: improve test coverage This commit adds two new tests to cover lines of the Generic.PHP.NoSiliencedErrors that were not covered previously. One has to do with a sniff property that allows users to set this sniff as an error instead of a warning (default value) and the other with calculating $contextLength when its value should be smaller than the default value of 4. --- .../Generic/Tests/PHP/NoSilencedErrorsUnitTest.inc | 6 ++++++ .../Generic/Tests/PHP/NoSilencedErrorsUnitTest.php | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.inc b/src/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.inc index 72bffe2c4c..98159b4725 100644 --- a/src/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.inc +++ b/src/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.inc @@ -8,3 +8,9 @@ if (@in_array($array, $needle)) } $hasValue = @in_array(haystack: $array, needle: $needle); + +// phpcs:set Generic.PHP.NoSilencedErrors error true +$fileContent = @file_get_contents('non_existent_file.txt'); +// phpcs:set Generic.PHP.NoSilencedErrors error false + +echo @$undefinedVariable; diff --git a/src/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.php b/src/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.php index dc7e754d51..43f762812b 100644 --- a/src/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.php +++ b/src/Standards/Generic/Tests/PHP/NoSilencedErrorsUnitTest.php @@ -30,7 +30,7 @@ class NoSilencedErrorsUnitTest extends AbstractSniffUnitTest */ public function getErrorList() { - return []; + return [13 => 1]; }//end getErrorList() @@ -48,6 +48,7 @@ public function getWarningList() return [ 5 => 1, 10 => 1, + 16 => 1, ]; }//end getWarningList()