File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed
Tests/VariableAnalysisSniff Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace VariableAnalysis \Tests \VariableAnalysisSniff ;
3+
4+ use VariableAnalysis \Tests \BaseTestCase ;
5+
6+ class GlobalScopeTest extends BaseTestCase {
7+ public function testGlobalScopeWarnings () {
8+ $ fixtureFile = $ this ->getFixture ('GlobalScopeFixture.php ' );
9+ $ phpcsFile = $ this ->prepareLocalFileForSniffs ($ fixtureFile );
10+ $ phpcsFile ->ruleset ->setSniffProperty (
11+ 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff ' ,
12+ 'allowUndefinedVariablesInFileScope ' ,
13+ 'false '
14+ );
15+ $ phpcsFile ->process ();
16+ $ lines = $ this ->getWarningLineNumbersFromFile ($ phpcsFile );
17+ $ expectedErrors = [
18+ 4 ,
19+ 7 ,
20+ 10 ,
21+ ];
22+ $ this ->assertEquals ($ expectedErrors , $ lines );
23+ }
24+
25+ public function testGlobalScopeWarningsWithAllowUndefinedVariablesInFileScope () {
26+ $ fixtureFile = $ this ->getFixture ('GlobalScopeFixture.php ' );
27+ $ phpcsFile = $ this ->prepareLocalFileForSniffs ($ fixtureFile );
28+ $ phpcsFile ->ruleset ->setSniffProperty (
29+ 'VariableAnalysis\Sniffs\CodeAnalysis\VariableAnalysisSniff ' ,
30+ 'allowUndefinedVariablesInFileScope ' ,
31+ 'true '
32+ );
33+ $ phpcsFile ->process ();
34+ $ lines = $ this ->getWarningLineNumbersFromFile ($ phpcsFile );
35+ $ expectedErrors = [
36+ 4 ,
37+ 10 ,
38+ ];
39+ $ this ->assertEquals ($ expectedErrors , $ lines );
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ $ name = 'friend ' ;
4+ $ place = 'faerie ' ; // unused variable $place
5+
6+ echo $ name ;
7+ echo $ activity ; // undefined variable $activity
8+
9+ function thisIsAFunction () {
10+ echo $ whatever ; // undefined variable $whatever
11+ }
You can’t perform that action at this time.
0 commit comments