Skip to content

Commit

Permalink
Generic/EmptyPHPStatement: add tests for the short open tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigoprimo authored and jrfnl committed Nov 26, 2024
1 parent 586bf86 commit f6c5682
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Tests with short open tag. -->

<input name="<? ; something_else(); ?>" />
<input name="<? something_else(); ; ?>" />

/*
* Test empty statement: no code between PHP open and close tag.
*/
<input name="<? something_else() ?>" /> <!-- OK. -->
<input name="<? something_else(); ?>" /> <!-- OK. -->
<input name="<? /* comment */ ?>" /> <!-- OK. -->

<input name="<? ?>" /> <!-- Bad. -->

<input name="<?


?>" /> <!-- Bad. -->

<!--
/*
* Test detecting & fixing a combination of the two checks.
*/
-->
<? ; ?>

<input name="<? ; ?>" /> <!-- Bad. -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Tests with short open tag. -->

<input name="<?something_else(); ?>" />
<input name="<? something_else(); ?>" />

/*
* Test empty statement: no code between PHP open and close tag.
*/
<input name="<? something_else() ?>" /> <!-- OK. -->
<input name="<? something_else(); ?>" /> <!-- OK. -->
<input name="<? /* comment */ ?>" /> <!-- OK. -->

<input name="" /> <!-- Bad. -->

<input name="" /> <!-- Bad. -->

<!--
/*
* Test detecting & fixing a combination of the two checks.
*/
-->

<input name="" /> <!-- Bad. -->
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ final class EmptyPHPStatementUnitTest extends AbstractSniffUnitTest
{


/**
* Get a list of all test files to check.
*
* @param string $testFileBase The base path that the unit tests files will have.
*
* @return string[]
*/
protected function getTestFiles($testFileBase)
{
$testFiles = [$testFileBase.'1.inc'];

$option = (bool) ini_get('short_open_tag');
if ($option === true) {
$testFiles[] = $testFileBase.'2.inc';
}

return $testFiles;

}//end getTestFiles()


/**
* Returns the lines where errors should occur.
*
Expand Down Expand Up @@ -70,6 +91,15 @@ public function getWarningList($testFile='')
72 => 1,
80 => 1,
];
case 'EmptyPHPStatementUnitTest.2.inc':
return [
3 => 1,
4 => 1,
13 => 1,
15 => 1,
25 => 1,
27 => 1,
];
default:
return [];
}//end switch
Expand Down

0 comments on commit f6c5682

Please sign in to comment.