From 615e820da98a0fa274c792df84d14b9cc156f865 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Fri, 26 Apr 2024 11:21:20 -0300 Subject: [PATCH] Generic/InlineControlStructure: improve code coverage --- .../InlineControlStructureUnitTest.1.inc | 19 +++++++++++++ ...InlineControlStructureUnitTest.1.inc.fixed | 23 +++++++++++++++ .../InlineControlStructureUnitTest.10.inc | 9 ++++++ ...nlineControlStructureUnitTest.10.inc.fixed | 10 +++++++ .../InlineControlStructureUnitTest.11.inc | 8 ++++++ ...nlineControlStructureUnitTest.11.inc.fixed | 9 ++++++ .../InlineControlStructureUnitTest.12.inc | 9 ++++++ .../InlineControlStructureUnitTest.13.inc | 13 +++++++++ .../InlineControlStructureUnitTest.8.inc | 7 +++++ .../InlineControlStructureUnitTest.9.inc | 7 +++++ .../InlineControlStructureUnitTest.php | 28 +++++++++++++++++-- 11 files changed, 140 insertions(+), 2 deletions(-) create mode 100644 src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.10.inc create mode 100644 src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.10.inc.fixed create mode 100644 src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.11.inc create mode 100644 src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.11.inc.fixed create mode 100644 src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.12.inc create mode 100644 src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.13.inc create mode 100644 src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.8.inc create mode 100644 src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.9.inc diff --git a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc index 1b02430859..617bfb9684 100644 --- a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc +++ b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc @@ -297,3 +297,22 @@ foreach ($array as $sniffShouldBailEarly) /* some comment */; do ; while ($sniffShouldBailEarly > 5); + +do echo $i++; while ($i < 5); + +// phpcs:set Generic.ControlStructures.InlineControlStructure error false +if ($something) echo 'hello'; +// phpcs:set Generic.ControlStructures.InlineControlStructure error true + +for ($i = 0; $i < 5; $i++) + if ($i === 3) { + echo 'three'; + } elseif ($i === 4) { + echo 'four'; + } elseif ($i === 5) { + echo 'five'; + } + +if ($noSpaceAfterClosingParenthesis)echo 'hello'; ?> + +scenario == 'simple' ) $widget->renderPager() ?> diff --git a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc.fixed b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc.fixed index ad03ad626f..649c023faa 100644 --- a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc.fixed +++ b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.1.inc.fixed @@ -336,3 +336,26 @@ foreach ($array as $sniffShouldBailEarly) /* some comment */; do ; while ($sniffShouldBailEarly > 5); + +do { echo $i++; +} while ($i < 5); + +// phpcs:set Generic.ControlStructures.InlineControlStructure error false +if ($something) { echo 'hello'; +} +// phpcs:set Generic.ControlStructures.InlineControlStructure error true + +for ($i = 0; $i < 5; $i++) { + if ($i === 3) { + echo 'three'; + } elseif ($i === 4) { + echo 'four'; + } elseif ($i === 5) { + echo 'five'; + } +} + +if ($noSpaceAfterClosingParenthesis) { echo 'hello'; +} ?> + +scenario == 'simple' ) { $widget->renderPager(); } ?> diff --git a/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.10.inc b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.10.inc new file mode 100644 index 0000000000..6de22da665 --- /dev/null +++ b/src/Standards/Generic/Tests/ControlStructures/InlineControlStructureUnitTest.10.inc @@ -0,0 +1,9 @@ + 1, 278 => 1, 289 => 1, + 301 => 1, + 307 => 1, + 316 => 1, + 318 => 1, + ]; + + case 'InlineControlStructureUnitTest.10.inc': + return [ + 6 => 1, + ]; + + case 'InlineControlStructureUnitTest.11.inc': + return [ + 7 => 1, ]; default: @@ -97,10 +111,20 @@ public function getErrorList($testFile = '') * The key of the array should represent the line number and the value * should represent the number of warnings that should occur on that line. * + * @param string $testFile The name of the file being tested. + * * @return array */ - public function getWarningList() + public function getWarningList($testFile = '') { - return []; + switch ($testFile) { + case 'InlineControlStructureUnitTest.1.inc': + return [ + 304 => 1, + ]; + + default: + return []; + } } }