Skip to content

Commit

Permalink
Generic/InlineControlStructure: improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoprimo committed May 7, 2024
1 parent 1c3e52f commit 62637ca
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,13 @@ if (false) {
} else ($shouldTriggerSniff);

foreach ($array as $shouldNotTriggerSniff);

do echo $i++; while ($i < 5);

// phpcs:set Generic.ControlStructures.InlineControlStructure error false
if ($something) echo 'hello';
// phpcs:set Generic.ControlStructures.InlineControlStructure error true

if ($noSpaceAfterClosingParenthesis)echo 'hello';

do ; while ($i > 5);
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,17 @@ if (false) {
}

foreach ($array as $shouldNotTriggerSniff);

do { echo $i++;
} while ($i < 5);

// phpcs:set Generic.ControlStructures.InlineControlStructure error false
if ($something) { echo 'hello';
}
// phpcs:set Generic.ControlStructures.InlineControlStructure error true

if ($noSpaceAfterClosingParenthesis) { echo 'hello';
}

do { ;
} while ($i > 5);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

// This should be the only test in this file.
// There should be only empty tokens after the scope closer of the "if" token.

for ($i = 0; $i < 5; $i++)
if ($i === 3) {
echo $i;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

// This should be the only test in this file.
// There should be only empty tokens after the scope closer of the "if" token.

for ($i = 0; $i < 5; $i++) {
if ($i === 3) {
echo $i;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error (nothing after for closing parenthesis).
// This should be the only test in this file.
// Testing that the sniff is *not* triggered.

for ($i = 0; $i < 5; $i++)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// Intentional parse error (nothing after while closing parenthesis).
// This should be the only test in this file.
// Testing that the sniff is *not* triggered.

while ($i < 5)
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public function getErrorList($testFile='')
269 => 1,
278 => 1,
289 => 1,
293 => 1,
299 => 1,
301 => 1,
];

case 'InlineControlStructureUnitTest.10.inc':
return [
6 => 1,
];

case 'InlineControlStructureUnitTest.1.js':
Expand Down Expand Up @@ -108,11 +116,21 @@ 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<int, int>
*/
public function getWarningList()
public function getWarningList($testFile='')
{
return [];
switch ($testFile) {
case 'InlineControlStructureUnitTest.1.inc':
return [
296 => 1,
];

default:
return [];
}

}//end getWarningList()

Expand Down

0 comments on commit 62637ca

Please # to comment.