comparison vendor/psy/psysh/test/Psy/Test/CodeCleaner/ValidFunctionNamePassTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 7a779792577d
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of Psy Shell.
5 *
6 * (c) 2012-2017 Justin Hileman
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Psy\Test\CodeCleaner;
13
14 use Psy\CodeCleaner\ValidFunctionNamePass;
15
16 class ValidFunctionNamePassTest extends CodeCleanerTestCase
17 {
18 public function setUp()
19 {
20 $this->setPass(new ValidFunctionNamePass());
21 }
22
23 /**
24 * @dataProvider getInvalidFunctions
25 * @expectedException \Psy\Exception\FatalErrorException
26 */
27 public function testProcessInvalidFunctionCallsAndDeclarations($code)
28 {
29 $stmts = $this->parse($code);
30 $this->traverse($stmts);
31 }
32
33 public function getInvalidFunctions()
34 {
35 return array(
36 // function declarations
37 array('function array_merge() {}'),
38 array('function Array_Merge() {}'),
39 array('
40 function psy_test_codecleaner_validfunctionnamepass_alpha() {}
41 function psy_test_codecleaner_validfunctionnamepass_alpha() {}
42 '),
43 array('
44 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
45 function beta() {}
46 }
47 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
48 function beta() {}
49 }
50 '),
51
52 // function calls
53 array('psy_test_codecleaner_validfunctionnamepass_gamma()'),
54 array('
55 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
56 delta();
57 }
58 '),
59
60 // recursion
61 array('function a() { a(); } function a() {}'),
62 );
63 }
64
65 /**
66 * @dataProvider getValidFunctions
67 */
68 public function testProcessValidFunctionCallsAndDeclarations($code)
69 {
70 $stmts = $this->parse($code);
71 $this->traverse($stmts);
72 }
73
74 public function getValidFunctions()
75 {
76 return array(
77 array('function psy_test_codecleaner_validfunctionnamepass_epsilon() {}'),
78 array('
79 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
80 function zeta() {}
81 }
82 '),
83 array('
84 namespace {
85 function psy_test_codecleaner_validfunctionnamepass_eta() {}
86 }
87 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
88 function psy_test_codecleaner_validfunctionnamepass_eta() {}
89 }
90 '),
91 array('
92 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
93 function psy_test_codecleaner_validfunctionnamepass_eta() {}
94 }
95 namespace {
96 function psy_test_codecleaner_validfunctionnamepass_eta() {}
97 }
98 '),
99 array('
100 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
101 function array_merge() {}
102 }
103 '),
104
105 // function calls
106 array('array_merge();'),
107 array('
108 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
109 function theta() {}
110 }
111 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
112 theta();
113 }
114 '),
115 // closures
116 array('$test = function(){};$test()'),
117 array('
118 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
119 function theta() {}
120 }
121 namespace {
122 Psy\\Test\\CodeCleaner\\ValidFunctionNamePass\\theta();
123 }
124 '),
125
126 // recursion
127 array('function a() { a(); }'),
128
129 // conditionally defined functions
130 array('
131 function a() {}
132 if (false) {
133 function a() {}
134 }
135 '),
136 array('
137 function a() {}
138 if (true) {
139 function a() {}
140 } else if (false) {
141 function a() {}
142 } else {
143 function a() {}
144 }
145 '),
146 // ewww
147 array('
148 function a() {}
149 if (true):
150 function a() {}
151 elseif (false):
152 function a() {}
153 else:
154 function a() {}
155 endif;
156 '),
157 array('
158 function a() {}
159 while (false) { function a() {} }
160 '),
161 array('
162 function a() {}
163 do { function a() {} } while (false);
164 '),
165 array('
166 function a() {}
167 switch (1) {
168 case 0:
169 function a() {}
170 break;
171 case 1:
172 function a() {}
173 break;
174 case 2:
175 function a() {}
176 break;
177 }
178 '),
179 );
180 }
181 }