DebugClassLoaderTest.php 35 KB

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