1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,448 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-/* |
|
4 |
- * This file is part of the Symfony package. |
|
5 |
- * |
|
6 |
- * (c) Fabien Potencier <fabien@symfony.com> |
|
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 Symfony\Component\Debug\Tests; |
|
13 |
- |
|
14 |
-use PHPUnit\Framework\TestCase; |
|
15 |
-use Symfony\Component\Debug\DebugClassLoader; |
|
16 |
- |
|
17 |
-class DebugClassLoaderTest extends TestCase |
|
18 |
-{ |
|
19 |
- /** |
|
20 |
- * @var int Error reporting level before running tests |
|
21 |
- */ |
|
22 |
- private $errorReporting; |
|
23 |
- |
|
24 |
- private $loader; |
|
25 |
- |
|
26 |
- protected function setUp() |
|
27 |
- { |
|
28 |
- $this->errorReporting = error_reporting(E_ALL); |
|
29 |
- $this->loader = new ClassLoader(); |
|
30 |
- spl_autoload_register([$this->loader, 'loadClass'], true, true); |
|
31 |
- DebugClassLoader::enable(); |
|
32 |
- } |
|
33 |
- |
|
34 |
- protected function tearDown() |
|
35 |
- { |
|
36 |
- DebugClassLoader::disable(); |
|
37 |
- spl_autoload_unregister([$this->loader, 'loadClass']); |
|
38 |
- error_reporting($this->errorReporting); |
|
39 |
- } |
|
40 |
- |
|
41 |
- public function testIdempotence() |
|
42 |
- { |
|
43 |
- DebugClassLoader::enable(); |
|
44 |
- |
|
45 |
- $functions = spl_autoload_functions(); |
|
46 |
- foreach ($functions as $function) { |
|
47 |
- if (\is_array($function) && $function[0] instanceof DebugClassLoader) { |
|
48 |
- $reflClass = new \ReflectionClass($function[0]); |
|
49 |
- $reflProp = $reflClass->getProperty('classLoader'); |
|
50 |
- $reflProp->setAccessible(true); |
|
51 |
- |
|
52 |
- $this->assertNotInstanceOf('Symfony\Component\Debug\DebugClassLoader', $reflProp->getValue($function[0])); |
|
53 |
- |
|
54 |
- return; |
|
55 |
- } |
|
56 |
- } |
|
57 |
- |
|
58 |
- $this->fail('DebugClassLoader did not register'); |
|
59 |
- } |
|
60 |
- |
|
61 |
- /** |
|
62 |
- * @expectedException \Exception |
|
63 |
- * @expectedExceptionMessage boo |
|
64 |
- */ |
|
65 |
- public function testThrowingClass() |
|
66 |
- { |
|
67 |
- try { |
|
68 |
- class_exists(__NAMESPACE__.'\Fixtures\Throwing'); |
|
69 |
- $this->fail('Exception expected'); |
|
70 |
- } catch (\Exception $e) { |
|
71 |
- $this->assertSame('boo', $e->getMessage()); |
|
72 |
- } |
|
73 |
- |
|
74 |
- // the second call also should throw |
|
75 |
- class_exists(__NAMESPACE__.'\Fixtures\Throwing'); |
|
76 |
- } |
|
77 |
- |
|
78 |
- /** |
|
79 |
- * @expectedException \RuntimeException |
|
80 |
- */ |
|
81 |
- public function testNameCaseMismatch() |
|
82 |
- { |
|
83 |
- class_exists(__NAMESPACE__.'\TestingCaseMismatch', true); |
|
84 |
- } |
|
85 |
- |
|
86 |
- /** |
|
87 |
- * @expectedException \RuntimeException |
|
88 |
- * @expectedExceptionMessage Case mismatch between class and real file names |
|
89 |
- */ |
|
90 |
- public function testFileCaseMismatch() |
|
91 |
- { |
|
92 |
- if (!file_exists(__DIR__.'/Fixtures/CaseMismatch.php')) { |
|
93 |
- $this->markTestSkipped('Can only be run on case insensitive filesystems'); |
|
94 |
- } |
|
95 |
- |
|
96 |
- class_exists(__NAMESPACE__.'\Fixtures\CaseMismatch', true); |
|
97 |
- } |
|
98 |
- |
|
99 |
- /** |
|
100 |
- * @expectedException \RuntimeException |
|
101 |
- */ |
|
102 |
- public function testPsr4CaseMismatch() |
|
103 |
- { |
|
104 |
- class_exists(__NAMESPACE__.'\Fixtures\Psr4CaseMismatch', true); |
|
105 |
- } |
|
106 |
- |
|
107 |
- public function testNotPsr0() |
|
108 |
- { |
|
109 |
- $this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\NotPSR0', true)); |
|
110 |
- } |
|
111 |
- |
|
112 |
- public function testNotPsr0Bis() |
|
113 |
- { |
|
114 |
- $this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\NotPSR0bis', true)); |
|
115 |
- } |
|
116 |
- |
|
117 |
- public function testClassAlias() |
|
118 |
- { |
|
119 |
- $this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\ClassAlias', true)); |
|
120 |
- } |
|
121 |
- |
|
122 |
- /** |
|
123 |
- * @dataProvider provideDeprecatedSuper |
|
124 |
- */ |
|
125 |
- public function testDeprecatedSuper($class, $super, $type) |
|
126 |
- { |
|
127 |
- set_error_handler(function () { return false; }); |
|
128 |
- $e = error_reporting(0); |
|
129 |
- trigger_error('', E_USER_DEPRECATED); |
|
130 |
- |
|
131 |
- class_exists('Test\\'.__NAMESPACE__.'\\'.$class, true); |
|
132 |
- |
|
133 |
- error_reporting($e); |
|
134 |
- restore_error_handler(); |
|
135 |
- |
|
136 |
- $lastError = error_get_last(); |
|
137 |
- unset($lastError['file'], $lastError['line']); |
|
138 |
- |
|
139 |
- $xError = [ |
|
140 |
- 'type' => E_USER_DEPRECATED, |
|
141 |
- 'message' => 'The "Test\Symfony\Component\Debug\Tests\\'.$class.'" class '.$type.' "Symfony\Component\Debug\Tests\Fixtures\\'.$super.'" that is deprecated but this is a test deprecation notice.', |
|
142 |
- ]; |
|
143 |
- |
|
144 |
- $this->assertSame($xError, $lastError); |
|
145 |
- } |
|
146 |
- |
|
147 |
- public function provideDeprecatedSuper() |
|
148 |
- { |
|
149 |
- return [ |
|
150 |
- ['DeprecatedInterfaceClass', 'DeprecatedInterface', 'implements'], |
|
151 |
- ['DeprecatedParentClass', 'DeprecatedClass', 'extends'], |
|
152 |
- ]; |
|
153 |
- } |
|
154 |
- |
|
155 |
- public function testInterfaceExtendsDeprecatedInterface() |
|
156 |
- { |
|
157 |
- set_error_handler(function () { return false; }); |
|
158 |
- $e = error_reporting(0); |
|
159 |
- trigger_error('', E_USER_NOTICE); |
|
160 |
- |
|
161 |
- class_exists('Test\\'.__NAMESPACE__.'\\NonDeprecatedInterfaceClass', true); |
|
162 |
- |
|
163 |
- error_reporting($e); |
|
164 |
- restore_error_handler(); |
|
165 |
- |
|
166 |
- $lastError = error_get_last(); |
|
167 |
- unset($lastError['file'], $lastError['line']); |
|
168 |
- |
|
169 |
- $xError = [ |
|
170 |
- 'type' => E_USER_NOTICE, |
|
171 |
- 'message' => '', |
|
172 |
- ]; |
|
173 |
- |
|
174 |
- $this->assertSame($xError, $lastError); |
|
175 |
- } |
|
176 |
- |
|
177 |
- public function testDeprecatedSuperInSameNamespace() |
|
178 |
- { |
|
179 |
- set_error_handler(function () { return false; }); |
|
180 |
- $e = error_reporting(0); |
|
181 |
- trigger_error('', E_USER_NOTICE); |
|
182 |
- |
|
183 |
- class_exists('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent', true); |
|
184 |
- |
|
185 |
- error_reporting($e); |
|
186 |
- restore_error_handler(); |
|
187 |
- |
|
188 |
- $lastError = error_get_last(); |
|
189 |
- unset($lastError['file'], $lastError['line']); |
|
190 |
- |
|
191 |
- $xError = [ |
|
192 |
- 'type' => E_USER_NOTICE, |
|
193 |
- 'message' => '', |
|
194 |
- ]; |
|
195 |
- |
|
196 |
- $this->assertSame($xError, $lastError); |
|
197 |
- } |
|
198 |
- |
|
199 |
- public function testExtendedFinalClass() |
|
200 |
- { |
|
201 |
- $deprecations = []; |
|
202 |
- set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
203 |
- $e = error_reporting(E_USER_DEPRECATED); |
|
204 |
- |
|
205 |
- require __DIR__.'/Fixtures/FinalClasses.php'; |
|
206 |
- |
|
207 |
- $i = 1; |
|
208 |
- while (class_exists($finalClass = __NAMESPACE__.'\\Fixtures\\FinalClass'.$i++, false)) { |
|
209 |
- spl_autoload_call($finalClass); |
|
210 |
- class_exists('Test\\'.__NAMESPACE__.'\\Extends'.substr($finalClass, strrpos($finalClass, '\\') + 1), true); |
|
211 |
- } |
|
212 |
- |
|
213 |
- error_reporting($e); |
|
214 |
- restore_error_handler(); |
|
215 |
- |
|
216 |
- $this->assertSame([ |
|
217 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass1" class is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass1".', |
|
218 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass2" class is considered final. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass2".', |
|
219 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass3" class is considered final comment with @@@ and ***. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass3".', |
|
220 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass4" class is considered final. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass4".', |
|
221 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass5" class is considered final multiline comment. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass5".', |
|
222 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass6" class is considered final. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass6".', |
|
223 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass7" class is considered final another multiline comment... It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass7".', |
|
224 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass8" class is considered final. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass8".', |
|
225 |
- ], $deprecations); |
|
226 |
- } |
|
227 |
- |
|
228 |
- public function testExtendedFinalMethod() |
|
229 |
- { |
|
230 |
- $deprecations = []; |
|
231 |
- set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
232 |
- $e = error_reporting(E_USER_DEPRECATED); |
|
233 |
- |
|
234 |
- class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true); |
|
235 |
- |
|
236 |
- error_reporting($e); |
|
237 |
- restore_error_handler(); |
|
238 |
- |
|
239 |
- $xError = [ |
|
240 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".', |
|
241 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod2()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".', |
|
242 |
- ]; |
|
243 |
- |
|
244 |
- $this->assertSame($xError, $deprecations); |
|
245 |
- } |
|
246 |
- |
|
247 |
- public function testExtendedDeprecatedMethodDoesntTriggerAnyNotice() |
|
248 |
- { |
|
249 |
- set_error_handler(function () { return false; }); |
|
250 |
- $e = error_reporting(0); |
|
251 |
- trigger_error('', E_USER_NOTICE); |
|
252 |
- |
|
253 |
- class_exists('Test\\'.__NAMESPACE__.'\\ExtendsAnnotatedClass', true); |
|
254 |
- |
|
255 |
- error_reporting($e); |
|
256 |
- restore_error_handler(); |
|
257 |
- |
|
258 |
- $lastError = error_get_last(); |
|
259 |
- unset($lastError['file'], $lastError['line']); |
|
260 |
- |
|
261 |
- $this->assertSame(['type' => E_USER_NOTICE, 'message' => ''], $lastError); |
|
262 |
- } |
|
263 |
- |
|
264 |
- public function testInternalsUse() |
|
265 |
- { |
|
266 |
- $deprecations = []; |
|
267 |
- set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
268 |
- $e = error_reporting(E_USER_DEPRECATED); |
|
269 |
- |
|
270 |
- class_exists('Test\\'.__NAMESPACE__.'\\ExtendsInternals', true); |
|
271 |
- |
|
272 |
- error_reporting($e); |
|
273 |
- restore_error_handler(); |
|
274 |
- |
|
275 |
- $this->assertSame($deprecations, [ |
|
276 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\InternalInterface" interface is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternalsParent".', |
|
277 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass" class is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternalsParent".', |
|
278 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\InternalTrait" trait is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".', |
|
279 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass::internalMethod()" method is considered internal. It may change without further notice. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".', |
|
280 |
- ]); |
|
281 |
- } |
|
282 |
- |
|
283 |
- public function testExtendedMethodDefinesNewParameters() |
|
284 |
- { |
|
285 |
- $deprecations = []; |
|
286 |
- set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
287 |
- $e = error_reporting(E_USER_DEPRECATED); |
|
288 |
- |
|
289 |
- class_exists(__NAMESPACE__.'\\Fixtures\SubClassWithAnnotatedParameters', true); |
|
290 |
- |
|
291 |
- error_reporting($e); |
|
292 |
- restore_error_handler(); |
|
293 |
- |
|
294 |
- $this->assertSame([ |
|
295 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::quzMethod()" method will require a new "Quz $quz" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\ClassWithAnnotatedParameters", not defining it is deprecated.', |
|
296 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::whereAmI()" method will require a new "bool $matrix" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
297 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "$noType" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
298 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "callable(\Throwable|null $reason, mixed $value) $callback" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
299 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "string $param" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
300 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "callable ($a, $b) $anotherOne" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
301 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "Type$WithDollarIsStillAType $ccc" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
302 |
- 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::isSymfony()" method will require a new "true $yes" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\ClassWithAnnotatedParameters", not defining it is deprecated.', |
|
303 |
- ], $deprecations); |
|
304 |
- } |
|
305 |
- |
|
306 |
- public function testUseTraitWithInternalMethod() |
|
307 |
- { |
|
308 |
- $deprecations = []; |
|
309 |
- set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
310 |
- $e = error_reporting(E_USER_DEPRECATED); |
|
311 |
- |
|
312 |
- class_exists('Test\\'.__NAMESPACE__.'\\UseTraitWithInternalMethod', true); |
|
313 |
- |
|
314 |
- error_reporting($e); |
|
315 |
- restore_error_handler(); |
|
316 |
- |
|
317 |
- $this->assertSame([], $deprecations); |
|
318 |
- } |
|
319 |
- |
|
320 |
- public function testVirtualUse() |
|
321 |
- { |
|
322 |
- $deprecations = []; |
|
323 |
- set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
324 |
- $e = error_reporting(E_USER_DEPRECATED); |
|
325 |
- |
|
326 |
- class_exists('Test\\'.__NAMESPACE__.'\\ExtendsVirtual', true); |
|
327 |
- |
|
328 |
- error_reporting($e); |
|
329 |
- restore_error_handler(); |
|
330 |
- |
|
331 |
- $this->assertSame([ |
|
332 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::sameLineInterfaceMethodNoBraces()".', |
|
333 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::newLineInterfaceMethod()": Some description!', |
|
334 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::newLineInterfaceMethodNoBraces()": Description.', |
|
335 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::invalidInterfaceMethod()".', |
|
336 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::invalidInterfaceMethodNoBraces()".', |
|
337 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::complexInterfaceMethod($arg, ...$args)".', |
|
338 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::complexInterfaceMethodTyped($arg, int ...$args)": Description ...', |
|
339 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "static Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::staticMethodNoBraces()".', |
|
340 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "static Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::staticMethodTyped(int $arg)": Description.', |
|
341 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "static Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::staticMethodTypedNoBraces()".', |
|
342 |
- 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtual" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualSubInterface::subInterfaceMethod()".', |
|
343 |
- ], $deprecations); |
|
344 |
- } |
|
345 |
- |
|
346 |
- public function testVirtualUseWithMagicCall() |
|
347 |
- { |
|
348 |
- $deprecations = []; |
|
349 |
- set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
350 |
- $e = error_reporting(E_USER_DEPRECATED); |
|
351 |
- |
|
352 |
- class_exists('Test\\'.__NAMESPACE__.'\\ExtendsVirtualMagicCall', true); |
|
353 |
- |
|
354 |
- error_reporting($e); |
|
355 |
- restore_error_handler(); |
|
356 |
- |
|
357 |
- $this->assertSame([], $deprecations); |
|
358 |
- } |
|
359 |
- |
|
360 |
- public function testEvaluatedCode() |
|
361 |
- { |
|
362 |
- $this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\DefinitionInEvaluatedCode', true)); |
|
363 |
- } |
|
364 |
-} |
|
365 |
- |
|
366 |
-class ClassLoader |
|
367 |
-{ |
|
368 |
- public function loadClass($class) |
|
369 |
- { |
|
370 |
- } |
|
371 |
- |
|
372 |
- public function getClassMap() |
|
373 |
- { |
|
374 |
- return [__NAMESPACE__.'\Fixtures\NotPSR0bis' => __DIR__.'/Fixtures/notPsr0Bis.php']; |
|
375 |
- } |
|
376 |
- |
|
377 |
- public function findFile($class) |
|
378 |
- { |
|
379 |
- $fixtureDir = __DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR; |
|
380 |
- |
|
381 |
- if (__NAMESPACE__.'\TestingUnsilencing' === $class) { |
|
382 |
- eval('-- parse error --'); |
|
383 |
- } elseif (__NAMESPACE__.'\TestingStacking' === $class) { |
|
384 |
- eval('namespace '.__NAMESPACE__.'; class TestingStacking { function foo() {} }'); |
|
385 |
- } elseif (__NAMESPACE__.'\TestingCaseMismatch' === $class) { |
|
386 |
- eval('namespace '.__NAMESPACE__.'; class TestingCaseMisMatch {}'); |
|
387 |
- } elseif (__NAMESPACE__.'\Fixtures\Psr4CaseMismatch' === $class) { |
|
388 |
- return $fixtureDir.'psr4'.\DIRECTORY_SEPARATOR.'Psr4CaseMismatch.php'; |
|
389 |
- } elseif (__NAMESPACE__.'\Fixtures\NotPSR0' === $class) { |
|
390 |
- return $fixtureDir.'reallyNotPsr0.php'; |
|
391 |
- } elseif (__NAMESPACE__.'\Fixtures\NotPSR0bis' === $class) { |
|
392 |
- return $fixtureDir.'notPsr0Bis.php'; |
|
393 |
- } elseif ('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent' === $class) { |
|
394 |
- eval('namespace Symfony\Bridge\Debug\Tests\Fixtures; class ExtendsDeprecatedParent extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}'); |
|
395 |
- } elseif ('Test\\'.__NAMESPACE__.'\DeprecatedParentClass' === $class) { |
|
396 |
- eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedParentClass extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}'); |
|
397 |
- } elseif ('Test\\'.__NAMESPACE__.'\DeprecatedInterfaceClass' === $class) { |
|
398 |
- eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\DeprecatedInterface {}'); |
|
399 |
- } elseif ('Test\\'.__NAMESPACE__.'\NonDeprecatedInterfaceClass' === $class) { |
|
400 |
- eval('namespace Test\\'.__NAMESPACE__.'; class NonDeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\NonDeprecatedInterface {}'); |
|
401 |
- } elseif ('Test\\'.__NAMESPACE__.'\Float' === $class) { |
|
402 |
- eval('namespace Test\\'.__NAMESPACE__.'; class Float {}'); |
|
403 |
- } elseif (0 === strpos($class, 'Test\\'.__NAMESPACE__.'\ExtendsFinalClass')) { |
|
404 |
- $classShortName = substr($class, strrpos($class, '\\') + 1); |
|
405 |
- eval('namespace Test\\'.__NAMESPACE__.'; class '.$classShortName.' extends \\'.__NAMESPACE__.'\Fixtures\\'.substr($classShortName, 7).' {}'); |
|
406 |
- } elseif ('Test\\'.__NAMESPACE__.'\ExtendsAnnotatedClass' === $class) { |
|
407 |
- eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsAnnotatedClass extends \\'.__NAMESPACE__.'\Fixtures\AnnotatedClass { |
|
408 |
- public function deprecatedMethod() { } |
|
409 |
- }'); |
|
410 |
- } elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternals' === $class) { |
|
411 |
- eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternals extends ExtendsInternalsParent { |
|
412 |
- use \\'.__NAMESPACE__.'\Fixtures\InternalTrait; |
|
413 |
- |
|
414 |
- public function internalMethod() { } |
|
415 |
- }'); |
|
416 |
- } elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternalsParent' === $class) { |
|
417 |
- eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternalsParent extends \\'.__NAMESPACE__.'\Fixtures\InternalClass implements \\'.__NAMESPACE__.'\Fixtures\InternalInterface { }'); |
|
418 |
- } elseif ('Test\\'.__NAMESPACE__.'\UseTraitWithInternalMethod' === $class) { |
|
419 |
- eval('namespace Test\\'.__NAMESPACE__.'; class UseTraitWithInternalMethod { use \\'.__NAMESPACE__.'\Fixtures\TraitWithInternalMethod; }'); |
|
420 |
- } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtual' === $class) { |
|
421 |
- eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsVirtual extends ExtendsVirtualParent implements \\'.__NAMESPACE__.'\Fixtures\VirtualSubInterface { |
|
422 |
- public function ownClassMethod() { } |
|
423 |
- public function classMethod() { } |
|
424 |
- public function sameLineInterfaceMethodNoBraces() { } |
|
425 |
- }'); |
|
426 |
- } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualParent' === $class) { |
|
427 |
- eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsVirtualParent extends ExtendsVirtualAbstract { |
|
428 |
- public function ownParentMethod() { } |
|
429 |
- public function traitMethod() { } |
|
430 |
- public function sameLineInterfaceMethod() { } |
|
431 |
- public function staticMethodNoBraces() { } // should be static |
|
432 |
- }'); |
|
433 |
- } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualAbstract' === $class) { |
|
434 |
- eval('namespace Test\\'.__NAMESPACE__.'; abstract class ExtendsVirtualAbstract extends ExtendsVirtualAbstractBase { |
|
435 |
- public static function staticMethod() { } |
|
436 |
- public function ownAbstractMethod() { } |
|
437 |
- public function interfaceMethod() { } |
|
438 |
- }'); |
|
439 |
- } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualAbstractBase' === $class) { |
|
440 |
- eval('namespace Test\\'.__NAMESPACE__.'; abstract class ExtendsVirtualAbstractBase extends \\'.__NAMESPACE__.'\Fixtures\VirtualClass implements \\'.__NAMESPACE__.'\Fixtures\VirtualInterface { |
|
441 |
- public function ownAbstractBaseMethod() { } |
|
442 |
- }'); |
|
443 |
- } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualMagicCall' === $class) { |
|
444 |
- eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsVirtualMagicCall extends \\'.__NAMESPACE__.'\Fixtures\VirtualClassMagicCall implements \\'.__NAMESPACE__.'\Fixtures\VirtualInterface { |
|
445 |
- }'); |
|
446 |
- } |
|
447 |
- } |
|
448 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,448 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/* |
|
4 |
+ * This file is part of the Symfony package. |
|
5 |
+ * |
|
6 |
+ * (c) Fabien Potencier <fabien@symfony.com> |
|
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 Symfony\Component\Debug\Tests; |
|
13 |
+ |
|
14 |
+use PHPUnit\Framework\TestCase; |
|
15 |
+use Symfony\Component\Debug\DebugClassLoader; |
|
16 |
+ |
|
17 |
+class DebugClassLoaderTest extends TestCase |
|
18 |
+{ |
|
19 |
+ /** |
|
20 |
+ * @var int Error reporting level before running tests |
|
21 |
+ */ |
|
22 |
+ private $errorReporting; |
|
23 |
+ |
|
24 |
+ private $loader; |
|
25 |
+ |
|
26 |
+ protected function setUp() |
|
27 |
+ { |
|
28 |
+ $this->errorReporting = error_reporting(E_ALL); |
|
29 |
+ $this->loader = new ClassLoader(); |
|
30 |
+ spl_autoload_register([$this->loader, 'loadClass'], true, true); |
|
31 |
+ DebugClassLoader::enable(); |
|
32 |
+ } |
|
33 |
+ |
|
34 |
+ protected function tearDown() |
|
35 |
+ { |
|
36 |
+ DebugClassLoader::disable(); |
|
37 |
+ spl_autoload_unregister([$this->loader, 'loadClass']); |
|
38 |
+ error_reporting($this->errorReporting); |
|
39 |
+ } |
|
40 |
+ |
|
41 |
+ public function testIdempotence() |
|
42 |
+ { |
|
43 |
+ DebugClassLoader::enable(); |
|
44 |
+ |
|
45 |
+ $functions = spl_autoload_functions(); |
|
46 |
+ foreach ($functions as $function) { |
|
47 |
+ if (\is_array($function) && $function[0] instanceof DebugClassLoader) { |
|
48 |
+ $reflClass = new \ReflectionClass($function[0]); |
|
49 |
+ $reflProp = $reflClass->getProperty('classLoader'); |
|
50 |
+ $reflProp->setAccessible(true); |
|
51 |
+ |
|
52 |
+ $this->assertNotInstanceOf('Symfony\Component\Debug\DebugClassLoader', $reflProp->getValue($function[0])); |
|
53 |
+ |
|
54 |
+ return; |
|
55 |
+ } |
|
56 |
+ } |
|
57 |
+ |
|
58 |
+ $this->fail('DebugClassLoader did not register'); |
|
59 |
+ } |
|
60 |
+ |
|
61 |
+ /** |
|
62 |
+ * @expectedException \Exception |
|
63 |
+ * @expectedExceptionMessage boo |
|
64 |
+ */ |
|
65 |
+ public function testThrowingClass() |
|
66 |
+ { |
|
67 |
+ try { |
|
68 |
+ class_exists(__NAMESPACE__.'\Fixtures\Throwing'); |
|
69 |
+ $this->fail('Exception expected'); |
|
70 |
+ } catch (\Exception $e) { |
|
71 |
+ $this->assertSame('boo', $e->getMessage()); |
|
72 |
+ } |
|
73 |
+ |
|
74 |
+ // the second call also should throw |
|
75 |
+ class_exists(__NAMESPACE__.'\Fixtures\Throwing'); |
|
76 |
+ } |
|
77 |
+ |
|
78 |
+ /** |
|
79 |
+ * @expectedException \RuntimeException |
|
80 |
+ */ |
|
81 |
+ public function testNameCaseMismatch() |
|
82 |
+ { |
|
83 |
+ class_exists(__NAMESPACE__.'\TestingCaseMismatch', true); |
|
84 |
+ } |
|
85 |
+ |
|
86 |
+ /** |
|
87 |
+ * @expectedException \RuntimeException |
|
88 |
+ * @expectedExceptionMessage Case mismatch between class and real file names |
|
89 |
+ */ |
|
90 |
+ public function testFileCaseMismatch() |
|
91 |
+ { |
|
92 |
+ if (!file_exists(__DIR__.'/Fixtures/CaseMismatch.php')) { |
|
93 |
+ $this->markTestSkipped('Can only be run on case insensitive filesystems'); |
|
94 |
+ } |
|
95 |
+ |
|
96 |
+ class_exists(__NAMESPACE__.'\Fixtures\CaseMismatch', true); |
|
97 |
+ } |
|
98 |
+ |
|
99 |
+ /** |
|
100 |
+ * @expectedException \RuntimeException |
|
101 |
+ */ |
|
102 |
+ public function testPsr4CaseMismatch() |
|
103 |
+ { |
|
104 |
+ class_exists(__NAMESPACE__.'\Fixtures\Psr4CaseMismatch', true); |
|
105 |
+ } |
|
106 |
+ |
|
107 |
+ public function testNotPsr0() |
|
108 |
+ { |
|
109 |
+ $this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\NotPSR0', true)); |
|
110 |
+ } |
|
111 |
+ |
|
112 |
+ public function testNotPsr0Bis() |
|
113 |
+ { |
|
114 |
+ $this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\NotPSR0bis', true)); |
|
115 |
+ } |
|
116 |
+ |
|
117 |
+ public function testClassAlias() |
|
118 |
+ { |
|
119 |
+ $this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\ClassAlias', true)); |
|
120 |
+ } |
|
121 |
+ |
|
122 |
+ /** |
|
123 |
+ * @dataProvider provideDeprecatedSuper |
|
124 |
+ */ |
|
125 |
+ public function testDeprecatedSuper($class, $super, $type) |
|
126 |
+ { |
|
127 |
+ set_error_handler(function () { return false; }); |
|
128 |
+ $e = error_reporting(0); |
|
129 |
+ trigger_error('', E_USER_DEPRECATED); |
|
130 |
+ |
|
131 |
+ class_exists('Test\\'.__NAMESPACE__.'\\'.$class, true); |
|
132 |
+ |
|
133 |
+ error_reporting($e); |
|
134 |
+ restore_error_handler(); |
|
135 |
+ |
|
136 |
+ $lastError = error_get_last(); |
|
137 |
+ unset($lastError['file'], $lastError['line']); |
|
138 |
+ |
|
139 |
+ $xError = [ |
|
140 |
+ 'type' => E_USER_DEPRECATED, |
|
141 |
+ 'message' => 'The "Test\Symfony\Component\Debug\Tests\\'.$class.'" class '.$type.' "Symfony\Component\Debug\Tests\Fixtures\\'.$super.'" that is deprecated but this is a test deprecation notice.', |
|
142 |
+ ]; |
|
143 |
+ |
|
144 |
+ $this->assertSame($xError, $lastError); |
|
145 |
+ } |
|
146 |
+ |
|
147 |
+ public function provideDeprecatedSuper() |
|
148 |
+ { |
|
149 |
+ return [ |
|
150 |
+ ['DeprecatedInterfaceClass', 'DeprecatedInterface', 'implements'], |
|
151 |
+ ['DeprecatedParentClass', 'DeprecatedClass', 'extends'], |
|
152 |
+ ]; |
|
153 |
+ } |
|
154 |
+ |
|
155 |
+ public function testInterfaceExtendsDeprecatedInterface() |
|
156 |
+ { |
|
157 |
+ set_error_handler(function () { return false; }); |
|
158 |
+ $e = error_reporting(0); |
|
159 |
+ trigger_error('', E_USER_NOTICE); |
|
160 |
+ |
|
161 |
+ class_exists('Test\\'.__NAMESPACE__.'\\NonDeprecatedInterfaceClass', true); |
|
162 |
+ |
|
163 |
+ error_reporting($e); |
|
164 |
+ restore_error_handler(); |
|
165 |
+ |
|
166 |
+ $lastError = error_get_last(); |
|
167 |
+ unset($lastError['file'], $lastError['line']); |
|
168 |
+ |
|
169 |
+ $xError = [ |
|
170 |
+ 'type' => E_USER_NOTICE, |
|
171 |
+ 'message' => '', |
|
172 |
+ ]; |
|
173 |
+ |
|
174 |
+ $this->assertSame($xError, $lastError); |
|
175 |
+ } |
|
176 |
+ |
|
177 |
+ public function testDeprecatedSuperInSameNamespace() |
|
178 |
+ { |
|
179 |
+ set_error_handler(function () { return false; }); |
|
180 |
+ $e = error_reporting(0); |
|
181 |
+ trigger_error('', E_USER_NOTICE); |
|
182 |
+ |
|
183 |
+ class_exists('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent', true); |
|
184 |
+ |
|
185 |
+ error_reporting($e); |
|
186 |
+ restore_error_handler(); |
|
187 |
+ |
|
188 |
+ $lastError = error_get_last(); |
|
189 |
+ unset($lastError['file'], $lastError['line']); |
|
190 |
+ |
|
191 |
+ $xError = [ |
|
192 |
+ 'type' => E_USER_NOTICE, |
|
193 |
+ 'message' => '', |
|
194 |
+ ]; |
|
195 |
+ |
|
196 |
+ $this->assertSame($xError, $lastError); |
|
197 |
+ } |
|
198 |
+ |
|
199 |
+ public function testExtendedFinalClass() |
|
200 |
+ { |
|
201 |
+ $deprecations = []; |
|
202 |
+ set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
203 |
+ $e = error_reporting(E_USER_DEPRECATED); |
|
204 |
+ |
|
205 |
+ require __DIR__.'/Fixtures/FinalClasses.php'; |
|
206 |
+ |
|
207 |
+ $i = 1; |
|
208 |
+ while (class_exists($finalClass = __NAMESPACE__.'\\Fixtures\\FinalClass'.$i++, false)) { |
|
209 |
+ spl_autoload_call($finalClass); |
|
210 |
+ class_exists('Test\\'.__NAMESPACE__.'\\Extends'.substr($finalClass, strrpos($finalClass, '\\') + 1), true); |
|
211 |
+ } |
|
212 |
+ |
|
213 |
+ error_reporting($e); |
|
214 |
+ restore_error_handler(); |
|
215 |
+ |
|
216 |
+ $this->assertSame([ |
|
217 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass1" class is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass1".', |
|
218 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass2" class is considered final. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass2".', |
|
219 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass3" class is considered final comment with @@@ and ***. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass3".', |
|
220 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass4" class is considered final. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass4".', |
|
221 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass5" class is considered final multiline comment. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass5".', |
|
222 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass6" class is considered final. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass6".', |
|
223 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass7" class is considered final another multiline comment... It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass7".', |
|
224 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\FinalClass8" class is considered final. It may change without further notice as of its next major version. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsFinalClass8".', |
|
225 |
+ ], $deprecations); |
|
226 |
+ } |
|
227 |
+ |
|
228 |
+ public function testExtendedFinalMethod() |
|
229 |
+ { |
|
230 |
+ $deprecations = []; |
|
231 |
+ set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
232 |
+ $e = error_reporting(E_USER_DEPRECATED); |
|
233 |
+ |
|
234 |
+ class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true); |
|
235 |
+ |
|
236 |
+ error_reporting($e); |
|
237 |
+ restore_error_handler(); |
|
238 |
+ |
|
239 |
+ $xError = [ |
|
240 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".', |
|
241 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod2()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".', |
|
242 |
+ ]; |
|
243 |
+ |
|
244 |
+ $this->assertSame($xError, $deprecations); |
|
245 |
+ } |
|
246 |
+ |
|
247 |
+ public function testExtendedDeprecatedMethodDoesntTriggerAnyNotice() |
|
248 |
+ { |
|
249 |
+ set_error_handler(function () { return false; }); |
|
250 |
+ $e = error_reporting(0); |
|
251 |
+ trigger_error('', E_USER_NOTICE); |
|
252 |
+ |
|
253 |
+ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsAnnotatedClass', true); |
|
254 |
+ |
|
255 |
+ error_reporting($e); |
|
256 |
+ restore_error_handler(); |
|
257 |
+ |
|
258 |
+ $lastError = error_get_last(); |
|
259 |
+ unset($lastError['file'], $lastError['line']); |
|
260 |
+ |
|
261 |
+ $this->assertSame(['type' => E_USER_NOTICE, 'message' => ''], $lastError); |
|
262 |
+ } |
|
263 |
+ |
|
264 |
+ public function testInternalsUse() |
|
265 |
+ { |
|
266 |
+ $deprecations = []; |
|
267 |
+ set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
268 |
+ $e = error_reporting(E_USER_DEPRECATED); |
|
269 |
+ |
|
270 |
+ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsInternals', true); |
|
271 |
+ |
|
272 |
+ error_reporting($e); |
|
273 |
+ restore_error_handler(); |
|
274 |
+ |
|
275 |
+ $this->assertSame($deprecations, [ |
|
276 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\InternalInterface" interface is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternalsParent".', |
|
277 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass" class is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternalsParent".', |
|
278 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\InternalTrait" trait is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".', |
|
279 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass::internalMethod()" method is considered internal. It may change without further notice. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".', |
|
280 |
+ ]); |
|
281 |
+ } |
|
282 |
+ |
|
283 |
+ public function testExtendedMethodDefinesNewParameters() |
|
284 |
+ { |
|
285 |
+ $deprecations = []; |
|
286 |
+ set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
287 |
+ $e = error_reporting(E_USER_DEPRECATED); |
|
288 |
+ |
|
289 |
+ class_exists(__NAMESPACE__.'\\Fixtures\SubClassWithAnnotatedParameters', true); |
|
290 |
+ |
|
291 |
+ error_reporting($e); |
|
292 |
+ restore_error_handler(); |
|
293 |
+ |
|
294 |
+ $this->assertSame([ |
|
295 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::quzMethod()" method will require a new "Quz $quz" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\ClassWithAnnotatedParameters", not defining it is deprecated.', |
|
296 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::whereAmI()" method will require a new "bool $matrix" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
297 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "$noType" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
298 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "callable(\Throwable|null $reason, mixed $value) $callback" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
299 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "string $param" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
300 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "callable ($a, $b) $anotherOne" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
301 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::iAmHere()" method will require a new "Type$WithDollarIsStillAType $ccc" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\InterfaceWithAnnotatedParameters", not defining it is deprecated.', |
|
302 |
+ 'The "Symfony\Component\Debug\Tests\Fixtures\SubClassWithAnnotatedParameters::isSymfony()" method will require a new "true $yes" argument in the next major version of its parent class "Symfony\Component\Debug\Tests\Fixtures\ClassWithAnnotatedParameters", not defining it is deprecated.', |
|
303 |
+ ], $deprecations); |
|
304 |
+ } |
|
305 |
+ |
|
306 |
+ public function testUseTraitWithInternalMethod() |
|
307 |
+ { |
|
308 |
+ $deprecations = []; |
|
309 |
+ set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
310 |
+ $e = error_reporting(E_USER_DEPRECATED); |
|
311 |
+ |
|
312 |
+ class_exists('Test\\'.__NAMESPACE__.'\\UseTraitWithInternalMethod', true); |
|
313 |
+ |
|
314 |
+ error_reporting($e); |
|
315 |
+ restore_error_handler(); |
|
316 |
+ |
|
317 |
+ $this->assertSame([], $deprecations); |
|
318 |
+ } |
|
319 |
+ |
|
320 |
+ public function testVirtualUse() |
|
321 |
+ { |
|
322 |
+ $deprecations = []; |
|
323 |
+ set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
324 |
+ $e = error_reporting(E_USER_DEPRECATED); |
|
325 |
+ |
|
326 |
+ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsVirtual', true); |
|
327 |
+ |
|
328 |
+ error_reporting($e); |
|
329 |
+ restore_error_handler(); |
|
330 |
+ |
|
331 |
+ $this->assertSame([ |
|
332 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::sameLineInterfaceMethodNoBraces()".', |
|
333 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::newLineInterfaceMethod()": Some description!', |
|
334 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::newLineInterfaceMethodNoBraces()": Description.', |
|
335 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::invalidInterfaceMethod()".', |
|
336 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::invalidInterfaceMethodNoBraces()".', |
|
337 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::complexInterfaceMethod($arg, ...$args)".', |
|
338 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::complexInterfaceMethodTyped($arg, int ...$args)": Description ...', |
|
339 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "static Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::staticMethodNoBraces()".', |
|
340 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "static Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::staticMethodTyped(int $arg)": Description.', |
|
341 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtualParent" should implement method "static Symfony\Component\Debug\Tests\Fixtures\VirtualInterface::staticMethodTypedNoBraces()".', |
|
342 |
+ 'Class "Test\Symfony\Component\Debug\Tests\ExtendsVirtual" should implement method "Symfony\Component\Debug\Tests\Fixtures\VirtualSubInterface::subInterfaceMethod()".', |
|
343 |
+ ], $deprecations); |
|
344 |
+ } |
|
345 |
+ |
|
346 |
+ public function testVirtualUseWithMagicCall() |
|
347 |
+ { |
|
348 |
+ $deprecations = []; |
|
349 |
+ set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; }); |
|
350 |
+ $e = error_reporting(E_USER_DEPRECATED); |
|
351 |
+ |
|
352 |
+ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsVirtualMagicCall', true); |
|
353 |
+ |
|
354 |
+ error_reporting($e); |
|
355 |
+ restore_error_handler(); |
|
356 |
+ |
|
357 |
+ $this->assertSame([], $deprecations); |
|
358 |
+ } |
|
359 |
+ |
|
360 |
+ public function testEvaluatedCode() |
|
361 |
+ { |
|
362 |
+ $this->assertTrue(class_exists(__NAMESPACE__.'\Fixtures\DefinitionInEvaluatedCode', true)); |
|
363 |
+ } |
|
364 |
+} |
|
365 |
+ |
|
366 |
+class ClassLoader |
|
367 |
+{ |
|
368 |
+ public function loadClass($class) |
|
369 |
+ { |
|
370 |
+ } |
|
371 |
+ |
|
372 |
+ public function getClassMap() |
|
373 |
+ { |
|
374 |
+ return [__NAMESPACE__.'\Fixtures\NotPSR0bis' => __DIR__.'/Fixtures/notPsr0Bis.php']; |
|
375 |
+ } |
|
376 |
+ |
|
377 |
+ public function findFile($class) |
|
378 |
+ { |
|
379 |
+ $fixtureDir = __DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR; |
|
380 |
+ |
|
381 |
+ if (__NAMESPACE__.'\TestingUnsilencing' === $class) { |
|
382 |
+ eval('-- parse error --'); |
|
383 |
+ } elseif (__NAMESPACE__.'\TestingStacking' === $class) { |
|
384 |
+ eval('namespace '.__NAMESPACE__.'; class TestingStacking { function foo() {} }'); |
|
385 |
+ } elseif (__NAMESPACE__.'\TestingCaseMismatch' === $class) { |
|
386 |
+ eval('namespace '.__NAMESPACE__.'; class TestingCaseMisMatch {}'); |
|
387 |
+ } elseif (__NAMESPACE__.'\Fixtures\Psr4CaseMismatch' === $class) { |
|
388 |
+ return $fixtureDir.'psr4'.\DIRECTORY_SEPARATOR.'Psr4CaseMismatch.php'; |
|
389 |
+ } elseif (__NAMESPACE__.'\Fixtures\NotPSR0' === $class) { |
|
390 |
+ return $fixtureDir.'reallyNotPsr0.php'; |
|
391 |
+ } elseif (__NAMESPACE__.'\Fixtures\NotPSR0bis' === $class) { |
|
392 |
+ return $fixtureDir.'notPsr0Bis.php'; |
|
393 |
+ } elseif ('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent' === $class) { |
|
394 |
+ eval('namespace Symfony\Bridge\Debug\Tests\Fixtures; class ExtendsDeprecatedParent extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}'); |
|
395 |
+ } elseif ('Test\\'.__NAMESPACE__.'\DeprecatedParentClass' === $class) { |
|
396 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedParentClass extends \\'.__NAMESPACE__.'\Fixtures\DeprecatedClass {}'); |
|
397 |
+ } elseif ('Test\\'.__NAMESPACE__.'\DeprecatedInterfaceClass' === $class) { |
|
398 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class DeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\DeprecatedInterface {}'); |
|
399 |
+ } elseif ('Test\\'.__NAMESPACE__.'\NonDeprecatedInterfaceClass' === $class) { |
|
400 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class NonDeprecatedInterfaceClass implements \\'.__NAMESPACE__.'\Fixtures\NonDeprecatedInterface {}'); |
|
401 |
+ } elseif ('Test\\'.__NAMESPACE__.'\Float' === $class) { |
|
402 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class Float {}'); |
|
403 |
+ } elseif (0 === strpos($class, 'Test\\'.__NAMESPACE__.'\ExtendsFinalClass')) { |
|
404 |
+ $classShortName = substr($class, strrpos($class, '\\') + 1); |
|
405 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class '.$classShortName.' extends \\'.__NAMESPACE__.'\Fixtures\\'.substr($classShortName, 7).' {}'); |
|
406 |
+ } elseif ('Test\\'.__NAMESPACE__.'\ExtendsAnnotatedClass' === $class) { |
|
407 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsAnnotatedClass extends \\'.__NAMESPACE__.'\Fixtures\AnnotatedClass { |
|
408 |
+ public function deprecatedMethod() { } |
|
409 |
+ }'); |
|
410 |
+ } elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternals' === $class) { |
|
411 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternals extends ExtendsInternalsParent { |
|
412 |
+ use \\'.__NAMESPACE__.'\Fixtures\InternalTrait; |
|
413 |
+ |
|
414 |
+ public function internalMethod() { } |
|
415 |
+ }'); |
|
416 |
+ } elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternalsParent' === $class) { |
|
417 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternalsParent extends \\'.__NAMESPACE__.'\Fixtures\InternalClass implements \\'.__NAMESPACE__.'\Fixtures\InternalInterface { }'); |
|
418 |
+ } elseif ('Test\\'.__NAMESPACE__.'\UseTraitWithInternalMethod' === $class) { |
|
419 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class UseTraitWithInternalMethod { use \\'.__NAMESPACE__.'\Fixtures\TraitWithInternalMethod; }'); |
|
420 |
+ } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtual' === $class) { |
|
421 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsVirtual extends ExtendsVirtualParent implements \\'.__NAMESPACE__.'\Fixtures\VirtualSubInterface { |
|
422 |
+ public function ownClassMethod() { } |
|
423 |
+ public function classMethod() { } |
|
424 |
+ public function sameLineInterfaceMethodNoBraces() { } |
|
425 |
+ }'); |
|
426 |
+ } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualParent' === $class) { |
|
427 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsVirtualParent extends ExtendsVirtualAbstract { |
|
428 |
+ public function ownParentMethod() { } |
|
429 |
+ public function traitMethod() { } |
|
430 |
+ public function sameLineInterfaceMethod() { } |
|
431 |
+ public function staticMethodNoBraces() { } // should be static |
|
432 |
+ }'); |
|
433 |
+ } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualAbstract' === $class) { |
|
434 |
+ eval('namespace Test\\'.__NAMESPACE__.'; abstract class ExtendsVirtualAbstract extends ExtendsVirtualAbstractBase { |
|
435 |
+ public static function staticMethod() { } |
|
436 |
+ public function ownAbstractMethod() { } |
|
437 |
+ public function interfaceMethod() { } |
|
438 |
+ }'); |
|
439 |
+ } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualAbstractBase' === $class) { |
|
440 |
+ eval('namespace Test\\'.__NAMESPACE__.'; abstract class ExtendsVirtualAbstractBase extends \\'.__NAMESPACE__.'\Fixtures\VirtualClass implements \\'.__NAMESPACE__.'\Fixtures\VirtualInterface { |
|
441 |
+ public function ownAbstractBaseMethod() { } |
|
442 |
+ }'); |
|
443 |
+ } elseif ('Test\\'.__NAMESPACE__.'\ExtendsVirtualMagicCall' === $class) { |
|
444 |
+ eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsVirtualMagicCall extends \\'.__NAMESPACE__.'\Fixtures\VirtualClassMagicCall implements \\'.__NAMESPACE__.'\Fixtures\VirtualInterface { |
|
445 |
+ }'); |
|
446 |
+ } |
|
447 |
+ } |
|
448 |
+} |