66
77class ErrorTolerantConversionTest extends \PHPUnit \Framework \TestCase {
88 public function testIncompleteVar () {
9- $ incompleteContents = <<<'EOT'
9+ $ incomplete_contents = <<<'EOT'
1010<?php
1111function foo() {
1212 $a = $
1313}
1414EOT;
15- $ validContents = <<<'EOT'
15+ $ valid_contents = <<<'EOT'
1616<?php
1717function foo() {
1818
1919}
2020EOT;
21- $ this ->_testFallbackFromParser ($ incompleteContents , $ validContents );
21+ $ this ->_testFallbackFromParser ($ incomplete_contents , $ valid_contents );
2222 }
2323
2424 public function testIncompleteVarWithPlaceholder () {
25- $ incompleteContents = <<<'EOT'
25+ $ incomplete_contents = <<<'EOT'
2626<?php
2727function foo() {
2828 $a = $
2929}
3030EOT;
31- $ validContents = <<<'EOT'
31+ $ valid_contents = <<<'EOT'
3232<?php
3333function foo() {
3434 $a = $__INCOMPLETE_VARIABLE__;
3535}
3636EOT;
37- $ this ->_testFallbackFromParser ($ incompleteContents , $ validContents , true );
37+ $ this ->_testFallbackFromParser ($ incomplete_contents , $ valid_contents , true );
3838 }
3939
4040 public function testIncompleteProperty () {
41- $ incompleteContents = <<<'EOT'
41+ $ incomplete_contents = <<<'EOT'
4242<?php
4343function foo() {
4444 $c;
4545 $a = $b->
4646}
4747EOT;
48- $ validContents = <<<'EOT'
48+ $ valid_contents = <<<'EOT'
4949<?php
5050function foo() {
5151 $c;
5252
5353}
5454EOT;
55- $ this ->_testFallbackFromParser ($ incompleteContents , $ validContents );
55+ $ this ->_testFallbackFromParser ($ incomplete_contents , $ valid_contents );
5656 }
5757
5858 public function testIncompletePropertyWithPlaceholder () {
59- $ incompleteContents = <<<'EOT'
59+ $ incomplete_contents = <<<'EOT'
6060<?php
6161function foo() {
6262 $c;
6363 $a = $b->
6464}
6565EOT;
66- $ validContents = <<<'EOT'
66+ $ valid_contents = <<<'EOT'
6767<?php
6868function foo() {
6969 $c;
7070 $a = $b->__INCOMPLETE_PROPERTY__;
7171}
7272EOT;
73- $ this ->_testFallbackFromParser ($ incompleteContents , $ validContents , true );
73+ $ this ->_testFallbackFromParser ($ incomplete_contents , $ valid_contents , true );
7474 }
7575
7676 public function testIncompleteMethod () {
77- $ incompleteContents = <<<'EOT'
77+ $ incomplete_contents = <<<'EOT'
7878<?php
7979function foo() {
8080 $b;
8181 $a = Bar::
8282}
8383EOT;
84- $ validContents = <<<'EOT'
84+ $ valid_contents = <<<'EOT'
8585<?php
8686function foo() {
8787 $b;
8888
8989}
9090EOT;
91- $ this ->_testFallbackFromParser ($ incompleteContents , $ validContents );
91+ $ this ->_testFallbackFromParser ($ incomplete_contents , $ valid_contents );
9292 }
9393
9494 public function testIncompleteMethodWithPlaceholder () {
95- $ incompleteContents = <<<'EOT'
95+ $ incomplete_contents = <<<'EOT'
9696<?php
9797function foo() {
9898 $b;
9999 $a = Bar::
100100}
101101EOT;
102- $ validContents = <<<'EOT'
102+ $ valid_contents = <<<'EOT'
103103<?php
104104function foo() {
105105 $b;
106106 $a = Bar::__INCOMPLETE_CLASS_CONST__;
107107}
108108EOT;
109- $ this ->_testFallbackFromParser ($ incompleteContents , $ validContents , true );
109+ $ this ->_testFallbackFromParser ($ incomplete_contents , $ valid_contents , true );
110110 }
111111
112112 public function testMiscNoise () {
113- $ incompleteContents = <<<'EOT'
113+ $ incomplete_contents = <<<'EOT'
114114<?php
115115function foo() {
116116 $b;
117117 |
118118}
119119EOT;
120- $ validContents = <<<'EOT'
120+ $ valid_contents = <<<'EOT'
121121<?php
122122function foo() {
123123 $b;
124124
125125}
126126EOT;
127- $ this ->_testFallbackFromParser ($ incompleteContents , $ validContents );
127+ $ this ->_testFallbackFromParser ($ incomplete_contents , $ valid_contents );
128128 }
129129
130130 public function testMiscNoiseWithPlaceholders () {
131- $ incompleteContents = <<<'EOT'
131+ $ incomplete_contents = <<<'EOT'
132132<?php
133133function foo() {
134134 $b;
135135 |
136136}
137137EOT;
138- $ validContents = <<<'EOT'
138+ $ valid_contents = <<<'EOT'
139139<?php
140140function foo() {
141141 $b;
142142
143143}
144144EOT;
145- $ this ->_testFallbackFromParser ($ incompleteContents , $ validContents , true );
145+ $ this ->_testFallbackFromParser ($ incomplete_contents , $ valid_contents , true );
146146 }
147147
148148 public function testIncompleteArithmeticWithPlaceholders () {
149- $ incompleteContents = <<<'EOT'
149+ $ incomplete_contents = <<<'EOT'
150150<?php
151151function foo() {
152152 ($b * $c) +
153153}
154154EOT;
155- $ validContents = <<<'EOT'
155+ $ valid_contents = <<<'EOT'
156156<?php
157157function foo() {
158158 $b * $c;
159159}
160160EOT;
161- $ this ->_testFallbackFromParser ($ incompleteContents , $ validContents , true );
161+ $ this ->_testFallbackFromParser ($ incomplete_contents , $ valid_contents , true );
162162 }
163163
164164 public function testMissingSemicolon () {
165- $ incompleteContents = <<<'EOT'
165+ $ incomplete_contents = <<<'EOT'
166166<?php
167167function foo() {
168168 $y = 3
169169 $x = intdiv(3, 2);
170170}
171171EOT;
172- $ validContents = <<<'EOT'
172+ $ valid_contents = <<<'EOT'
173173<?php
174174function foo() {
175175 $y = 3;
176176 $x = intdiv(3, 2);
177177}
178178EOT;
179- $ this ->_testFallbackFromParser ($ incompleteContents , $ validContents );
179+ $ this ->_testFallbackFromParser ($ incomplete_contents , $ valid_contents );
180180 }
181181
182182// Another test (Won't work with php-parser, might work with tolerant-php-parser
183183/**
184- $incompleteContents = <<<'EOT'
184+ $incomplete_contents = <<<'EOT'
185185<?php
186186class C{
187187 public function foo() {
@@ -192,7 +192,7 @@ public function bar() {
192192 }
193193}
194194EOT;
195- $validContents = <<<'EOT'
195+ $valid_contents = <<<'EOT'
196196<?php
197197class C{
198198 public function foo() {
@@ -205,51 +205,51 @@ public function bar() {
205205EOT;
206206 */
207207
208- private function _testFallbackFromParser (string $ incompleteContents , string $ validContents , bool $ should_add_placeholders = false ) {
208+ private function _testFallbackFromParser (string $ incomplete_contents , string $ valid_contents , bool $ should_add_placeholders = false ) {
209209 $ supports40 = ConversionTest::hasNativeASTSupport (40 );
210210 $ supports50 = ConversionTest::hasNativeASTSupport (50 );
211211 if (!($ supports40 || $ supports50 )) {
212212 $ this ->fail ('No supported AST versions to test ' );
213213 }
214214 if ($ supports40 ) {
215- $ this ->_testFallbackFromParserForASTVersion ($ incompleteContents , $ validContents , 40 , $ should_add_placeholders );
215+ $ this ->_testFallbackFromParserForASTVersion ($ incomplete_contents , $ valid_contents , 40 , $ should_add_placeholders );
216216 }
217217 if ($ supports50 ) {
218- $ this ->_testFallbackFromParserForASTVersion ($ incompleteContents , $ validContents , 50 , $ should_add_placeholders );
218+ $ this ->_testFallbackFromParserForASTVersion ($ incomplete_contents , $ valid_contents , 50 , $ should_add_placeholders );
219219 }
220220 }
221221
222- private function _testFallbackFromParserForASTVersion (string $ incompleteContents , string $ validContents , int $ astVersion , bool $ should_add_placeholders ) {
223- $ ast = \ast \parse_code ($ validContents , $ astVersion );
222+ private function _testFallbackFromParserForASTVersion (string $ incomplete_contents , string $ valid_contents , int $ ast_version , bool $ should_add_placeholders ) {
223+ $ ast = \ast \parse_code ($ valid_contents , $ ast_version );
224224 $ this ->assertInstanceOf ('\ast\Node ' , $ ast , 'Examples(for validContents) must be syntactically valid PHP parseable by php-ast ' );
225225 $ errors = [];
226226 $ converter = new ASTConverter ();
227227 $ converter ->setShouldAddPlaceholders ($ should_add_placeholders );
228- $ phpParserNode = $ converter ->phpParserParse ($ incompleteContents , true , $ errors );
229- $ fallback_ast = $ converter ->phpParserToPhpAst ($ phpParserNode , $ astVersion );
228+ $ php_parser_node = $ converter ->phpParserParse ($ incomplete_contents , true , $ errors );
229+ $ fallback_ast = $ converter ->phpParserToPhpAst ($ php_parser_node , $ ast_version );
230230 $ this ->assertInstanceOf ('\ast\Node ' , $ fallback_ast , 'The fallback must also return a tree of php-ast nodes ' );
231- $ fallbackASTRepr = var_export ($ fallback_ast , true );
232- $ originalASTRepr = var_export ($ ast , true );
231+ $ fallbackAST_repr = var_export ($ fallback_ast , true );
232+ $ originalAST_repr = var_export ($ ast , true );
233233
234- if ($ fallbackASTRepr !== $ originalASTRepr ) {
234+ if ($ fallbackAST_repr !== $ originalAST_repr ) {
235235 $ dump = 'could not dump ' ;
236- $ nodeDumper = new \PhpParser \NodeDumper ([
236+ $ node_dumper = new \PhpParser \NodeDumper ([
237237 'dumpComments ' => true ,
238238 'dumpPositions ' => true ,
239239 ]);
240240 try {
241- $ dump = $ nodeDumper ->dump ($ phpParserNode );
241+ $ dump = $ node_dumper ->dump ($ php_parser_node );
242242 } catch (\PhpParser \Error $ e ) {
243243 }
244244 $ original_ast_dump = \ast_dump ($ ast );
245- // $parser_export = var_export($phpParserNode , true);
246- $ this ->assertSame ($ originalASTRepr , $ fallbackASTRepr , <<<EOT
245+ // $parser_export = var_export($php_parser_node , true);
246+ $ this ->assertSame ($ originalAST_repr , $ fallbackAST_repr , <<<EOT
247247The fallback must return the same tree of php-ast nodes
248248Code:
249- $ incompleteContents
249+ $ incomplete_contents
250250
251251Closest Valid Code:
252- $ validContents
252+ $ valid_contents
253253
254254Original AST:
255255$ original_ast_dump
0 commit comments