-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow parsing mixed HTML and PHP (#234)
* Add test for mixed html and php * Consider html and closing tags to be empty tokens * Remove explicit return type to support PHP 5.6 * Add additional test for sniff codes for closing tags fixture
- Loading branch information
1 parent
e76e816
commit 72cb4f9
Showing
3 changed files
with
78 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
namespace VariableAnalysis\Tests\VariableAnalysisSniff; | ||
|
||
use VariableAnalysis\Tests\BaseTestCase; | ||
|
||
class ClosingPhpTagsTest extends BaseTestCase { | ||
public function testVariableWarningsWhenClosingTagsAreUsed() { | ||
$fixtureFile = $this->getFixture('ClosingPhpTagsFixture.php'); | ||
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); | ||
$phpcsFile->process(); | ||
$lines = $this->getWarningLineNumbersFromFile($phpcsFile); | ||
$expectedWarnings = [ | ||
6, | ||
8, | ||
13, | ||
16, | ||
]; | ||
$this->assertEquals($expectedWarnings, $lines); | ||
} | ||
|
||
public function testVariableWarningsHaveCorrectSniffCodesWhenClosingTagsAreUsed() { | ||
$fixtureFile = $this->getFixture('ClosingPhpTagsFixture.php'); | ||
$phpcsFile = $this->prepareLocalFileForSniffs($fixtureFile); | ||
$phpcsFile->process(); | ||
$warnings = $phpcsFile->getWarnings(); | ||
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[6][1][0]['source']); | ||
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[8][6][0]['source']); | ||
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable', $warnings[13][1][0]['source']); | ||
$this->assertEquals('VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable', $warnings[16][6][0]['source']); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Tests/VariableAnalysisSniff/fixtures/ClosingPhpTagsFixture.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<html> | ||
<h1>Page Title</h1> | ||
<?php | ||
$foo = 'hello'; | ||
$blue = 'hello'; | ||
$bar = 'bye'; // unused variable | ||
echo $foo; | ||
echo $baz; // undefined variable | ||
?> | ||
<p>More stuff</p> | ||
<?php | ||
$foo2 = 'hello'; | ||
$bar2 = 'bye'; // unused variable | ||
echo $foo2; | ||
echo $blue; | ||
echo $baz2; // undefined variable | ||
?> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters