Skip to content

Commit 45e6cd7

Browse files
committed
Generic/EmptyPHPStatement: add tests for the short open tag
1 parent e540ffc commit 45e6cd7

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!-- Tests with short open echo tag. -->
2+
3+
<input name="<? ; something_else(); ?>" />
4+
<input name="<? something_else(); ; ?>" />
5+
6+
/*
7+
* Test empty statement: no code between PHP open and close tag.
8+
*/
9+
<input name="<? something_else() ?>" /> <!-- OK. -->
10+
<input name="<? something_else(); ?>" /> <!-- OK. -->
11+
<input name="<? /* comment */ ?>" /> <!-- OK. -->
12+
13+
<input name="<? ?>" /> <!-- Bad. -->
14+
15+
<input name="<?
16+
17+
18+
?>" /> <!-- Bad. -->
19+
20+
<!--
21+
/*
22+
* Test detecting & fixing a combination of the two checks.
23+
*/
24+
-->
25+
<? ; ?>
26+
27+
<input name="<? ; ?>" /> <!-- Bad. -->
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- Tests with short open echo tag. -->
2+
3+
<input name="<?something_else(); ?>" />
4+
<input name="<? something_else(); ?>" />
5+
6+
/*
7+
* Test empty statement: no code between PHP open and close tag.
8+
*/
9+
<input name="<? something_else() ?>" /> <!-- OK. -->
10+
<input name="<? something_else(); ?>" /> <!-- OK. -->
11+
<input name="<? /* comment */ ?>" /> <!-- OK. -->
12+
13+
<input name="" /> <!-- Bad. -->
14+
15+
<input name="" /> <!-- Bad. -->
16+
17+
<!--
18+
/*
19+
* Test detecting & fixing a combination of the two checks.
20+
*/
21+
-->
22+
23+
<input name="" /> <!-- Bad. -->

src/Standards/Generic/Tests/CodeAnalysis/EmptyPHPStatementUnitTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ final class EmptyPHPStatementUnitTest extends AbstractSniffUnitTest
2020
{
2121

2222

23+
/**
24+
* Get a list of all test files to check.
25+
*
26+
* @param string $testFileBase The base path that the unit tests files will have.
27+
*
28+
* @return string[]
29+
*/
30+
protected function getTestFiles($testFileBase)
31+
{
32+
$testFiles = [$testFileBase.'1.inc'];
33+
34+
$option = (bool) ini_get('short_open_tag');
35+
if ($option === true) {
36+
$testFiles[] = $testFileBase.'2.inc';
37+
}
38+
39+
return $testFiles;
40+
41+
}//end getTestFiles()
42+
43+
2344
/**
2445
* Returns the lines where errors should occur.
2546
*
@@ -70,6 +91,15 @@ public function getWarningList($testFile='')
7091
72 => 1,
7192
80 => 1,
7293
];
94+
case 'EmptyPHPStatementUnitTest.2.inc':
95+
return [
96+
3 => 1,
97+
4 => 1,
98+
13 => 1,
99+
15 => 1,
100+
25 => 1,
101+
27 => 1,
102+
];
73103
default:
74104
return [];
75105
}//end switch

0 commit comments

Comments
 (0)