9
9
10
10
namespace PHP_CodeSniffer \Tests \Core \File ;
11
11
12
- use PHP_CodeSniffer \Config ;
13
- use PHP_CodeSniffer \Ruleset ;
14
- use PHP_CodeSniffer \Files \DummyFile ;
15
- use PHPUnit \Framework \TestCase ;
12
+ use PHP_CodeSniffer \Tests \Core \AbstractMethodUnitTest ;
16
13
17
- class FindEndOfStatementTest extends TestCase
14
+ class FindEndOfStatementTest extends AbstractMethodUnitTest
18
15
{
19
16
20
- /**
21
- * The PHP_CodeSniffer_File object containing parsed contents of the test case file.
22
- *
23
- * @var \PHP_CodeSniffer\Files\File
24
- */
25
- private $ phpcsFile ;
26
-
27
-
28
- /**
29
- * Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file.
30
- *
31
- * Methods used for these tests can be found in a test case file in the same
32
- * directory and with the same name, using the .inc extension.
33
- *
34
- * @return void
35
- */
36
- public function setUp ()
37
- {
38
- $ config = new Config ();
39
- $ config ->standards = ['Generic ' ];
40
-
41
- $ ruleset = new Ruleset ($ config );
42
-
43
- $ pathToTestFile = dirname (__FILE__ ).'/ ' .basename (__FILE__ , '.php ' ).'.inc ' ;
44
- $ this ->phpcsFile = new DummyFile (file_get_contents ($ pathToTestFile ), $ ruleset , $ config );
45
- $ this ->phpcsFile ->process ();
46
-
47
- }//end setUp()
48
-
49
-
50
- /**
51
- * Clean up after finished test.
52
- *
53
- * @return void
54
- */
55
- public function tearDown ()
56
- {
57
- unset($ this ->phpcsFile );
58
-
59
- }//end tearDown()
60
-
61
17
62
18
/**
63
19
* Test a simple assignment.
@@ -66,10 +22,10 @@ public function tearDown()
66
22
*/
67
23
public function testSimpleAssignment ()
68
24
{
69
- $ start = ($ this -> phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testSimpleAssignment */ ' ) + 2 );
70
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
25
+ $ start = (self :: $ phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testSimpleAssignment */ ' ) + 2 );
26
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
71
27
72
- $ tokens = $ this -> phpcsFile ->getTokens ();
28
+ $ tokens = self :: $ phpcsFile ->getTokens ();
73
29
$ this ->assertSame ($ tokens [($ start + 5 )], $ tokens [$ found ]);
74
30
75
31
}//end testSimpleAssignment()
@@ -82,10 +38,10 @@ public function testSimpleAssignment()
82
38
*/
83
39
public function testControlStructure ()
84
40
{
85
- $ start = ($ this -> phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testControlStructure */ ' ) + 2 );
86
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
41
+ $ start = (self :: $ phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testControlStructure */ ' ) + 2 );
42
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
87
43
88
- $ tokens = $ this -> phpcsFile ->getTokens ();
44
+ $ tokens = self :: $ phpcsFile ->getTokens ();
89
45
$ this ->assertSame ($ tokens [($ start + 6 )], $ tokens [$ found ]);
90
46
91
47
}//end testControlStructure()
@@ -98,10 +54,10 @@ public function testControlStructure()
98
54
*/
99
55
public function testClosureAssignment ()
100
56
{
101
- $ start = ($ this -> phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testClosureAssignment */ ' ) + 2 );
102
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
57
+ $ start = (self :: $ phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testClosureAssignment */ ' ) + 2 );
58
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
103
59
104
- $ tokens = $ this -> phpcsFile ->getTokens ();
60
+ $ tokens = self :: $ phpcsFile ->getTokens ();
105
61
$ this ->assertSame ($ tokens [($ start + 13 )], $ tokens [$ found ]);
106
62
107
63
}//end testClosureAssignment()
@@ -115,24 +71,24 @@ public function testClosureAssignment()
115
71
public function testHeredocFunctionArg ()
116
72
{
117
73
// Find the end of the function.
118
- $ start = ($ this -> phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testHeredocFunctionArg */ ' ) + 2 );
119
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
74
+ $ start = (self :: $ phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testHeredocFunctionArg */ ' ) + 2 );
75
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
120
76
121
- $ tokens = $ this -> phpcsFile ->getTokens ();
77
+ $ tokens = self :: $ phpcsFile ->getTokens ();
122
78
$ this ->assertSame ($ tokens [($ start + 10 )], $ tokens [$ found ]);
123
79
124
80
// Find the end of the heredoc.
125
81
$ start += 2 ;
126
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
82
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
127
83
128
- $ tokens = $ this -> phpcsFile ->getTokens ();
84
+ $ tokens = self :: $ phpcsFile ->getTokens ();
129
85
$ this ->assertSame ($ tokens [($ start + 4 )], $ tokens [$ found ]);
130
86
131
87
// Find the end of the last arg.
132
88
$ start = ($ found + 2 );
133
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
89
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
134
90
135
- $ tokens = $ this -> phpcsFile ->getTokens ();
91
+ $ tokens = self :: $ phpcsFile ->getTokens ();
136
92
$ this ->assertSame ($ tokens [$ start ], $ tokens [$ found ]);
137
93
138
94
}//end testHeredocFunctionArg()
@@ -146,24 +102,24 @@ public function testHeredocFunctionArg()
146
102
public function testSwitch ()
147
103
{
148
104
// Find the end of the switch.
149
- $ start = ($ this -> phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testSwitch */ ' ) + 2 );
150
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
105
+ $ start = (self :: $ phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testSwitch */ ' ) + 2 );
106
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
151
107
152
- $ tokens = $ this -> phpcsFile ->getTokens ();
108
+ $ tokens = self :: $ phpcsFile ->getTokens ();
153
109
$ this ->assertSame ($ tokens [($ start + 28 )], $ tokens [$ found ]);
154
110
155
111
// Find the end of the case.
156
112
$ start += 9 ;
157
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
113
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
158
114
159
- $ tokens = $ this -> phpcsFile ->getTokens ();
115
+ $ tokens = self :: $ phpcsFile ->getTokens ();
160
116
$ this ->assertSame ($ tokens [($ start + 8 )], $ tokens [$ found ]);
161
117
162
118
// Find the end of default case.
163
119
$ start += 11 ;
164
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
120
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
165
121
166
- $ tokens = $ this -> phpcsFile ->getTokens ();
122
+ $ tokens = self :: $ phpcsFile ->getTokens ();
167
123
$ this ->assertSame ($ tokens [($ start + 6 )], $ tokens [$ found ]);
168
124
169
125
}//end testSwitch()
@@ -177,24 +133,24 @@ public function testSwitch()
177
133
public function testStatementAsArrayValue ()
178
134
{
179
135
// Test short array syntax.
180
- $ start = ($ this -> phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testStatementAsArrayValue */ ' ) + 7 );
181
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
136
+ $ start = (self :: $ phpcsFile ->findNext (T_COMMENT , 0 , null , false , '/* testStatementAsArrayValue */ ' ) + 7 );
137
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
182
138
183
- $ tokens = $ this -> phpcsFile ->getTokens ();
139
+ $ tokens = self :: $ phpcsFile ->getTokens ();
184
140
$ this ->assertSame ($ tokens [($ start + 2 )], $ tokens [$ found ]);
185
141
186
142
// Test long array syntax.
187
143
$ start += 12 ;
188
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
144
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
189
145
190
- $ tokens = $ this -> phpcsFile ->getTokens ();
146
+ $ tokens = self :: $ phpcsFile ->getTokens ();
191
147
$ this ->assertSame ($ tokens [($ start + 2 )], $ tokens [$ found ]);
192
148
193
149
// Test same statement outside of array.
194
150
$ start += 10 ;
195
- $ found = $ this -> phpcsFile ->findEndOfStatement ($ start );
151
+ $ found = self :: $ phpcsFile ->findEndOfStatement ($ start );
196
152
197
- $ tokens = $ this -> phpcsFile ->getTokens ();
153
+ $ tokens = self :: $ phpcsFile ->getTokens ();
198
154
$ this ->assertSame ($ tokens [($ start + 3 )], $ tokens [$ found ]);
199
155
200
156
}//end testStatementAsArrayValue()
0 commit comments