Updated from some -dev modules to alpha, beta or full releases
[yaffs-website] / vendor / psy / psysh / test / CodeCleaner / ValidFunctionNamePassTest.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2018 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         $this->parseAndTraverse($code);
30     }
31
32     public function getInvalidFunctions()
33     {
34         return [
35             // function declarations
36             ['function array_merge() {}'],
37             ['function Array_Merge() {}'],
38             ['
39                 function psy_test_codecleaner_validfunctionnamepass_alpha() {}
40                 function psy_test_codecleaner_validfunctionnamepass_alpha() {}
41             '],
42             ['
43                 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
44                     function beta() {}
45                 }
46                 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
47                     function beta() {}
48                 }
49             '],
50
51             // function calls
52             ['psy_test_codecleaner_validfunctionnamepass_gamma()'],
53             ['
54                 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
55                     delta();
56                 }
57             '],
58
59             // recursion
60             ['function a() { a(); } function a() {}'],
61         ];
62     }
63
64     /**
65      * @dataProvider getValidFunctions
66      */
67     public function testProcessValidFunctionCallsAndDeclarations($code)
68     {
69         $this->parseAndTraverse($code);
70         $this->assertTrue(true);
71     }
72
73     public function getValidFunctions()
74     {
75         return [
76             ['function psy_test_codecleaner_validfunctionnamepass_epsilon() {}'],
77             ['
78                 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
79                     function zeta() {}
80                 }
81             '],
82             ['
83                 namespace {
84                     function psy_test_codecleaner_validfunctionnamepass_eta() {}
85                 }
86                 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
87                     function psy_test_codecleaner_validfunctionnamepass_eta() {}
88                 }
89             '],
90             ['
91                 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
92                     function psy_test_codecleaner_validfunctionnamepass_eta() {}
93                 }
94                 namespace {
95                     function psy_test_codecleaner_validfunctionnamepass_eta() {}
96                 }
97             '],
98             ['
99                 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
100                     function array_merge() {}
101                 }
102             '],
103
104             // function calls
105             ['array_merge();'],
106             ['
107                 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
108                     function theta() {}
109                 }
110                 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
111                     theta();
112                 }
113             '],
114             // closures
115             ['$test = function(){};$test()'],
116             ['
117                 namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
118                     function theta() {}
119                 }
120                 namespace {
121                     Psy\\Test\\CodeCleaner\\ValidFunctionNamePass\\theta();
122                 }
123             '],
124
125             // recursion
126             ['function a() { a(); }'],
127
128             // conditionally defined functions
129             ['
130                 function a() {}
131                 if (false) {
132                     function a() {}
133                 }
134             '],
135             ['
136                 function a() {}
137                 if (true) {
138                     function a() {}
139                 } else if (false) {
140                     function a() {}
141                 } else {
142                     function a() {}
143                 }
144             '],
145             // ewww
146             ['
147                 function a() {}
148                 if (true):
149                     function a() {}
150                 elseif (false):
151                     function a() {}
152                 else:
153                     function a() {}
154                 endif;
155             '],
156             ['
157                 function a() {}
158                 while (false) { function a() {} }
159             '],
160             ['
161                 function a() {}
162                 do { function a() {} } while (false);
163             '],
164             ['
165                 function a() {}
166                 switch (1) {
167                     case 0:
168                         function a() {}
169                         break;
170                     case 1:
171                         function a() {}
172                         break;
173                     case 2:
174                         function a() {}
175                         break;
176                 }
177             '],
178         ];
179     }
180 }