From 2ba3cc0aba74e4fcfb323611e04687caaccc84dc Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Sep 2019 16:54:44 +0200 Subject: [PATCH] [ErrorHandler][Bridge/PhpUnit] display deprecations for not-autoloaded classes --- .../PhpUnit/DeprecationErrorHandler.php | 4 ++ .../Bridge/PhpUnit/bin/simple-phpunit.php | 2 +- .../ErrorHandler/DebugClassLoader.php | 49 +++++++++++++++++-- 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 5eb9179d7fadd..e15b62369384d 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -15,6 +15,7 @@ use PHPUnit\Util\ErrorHandler; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Configuration; use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation; +use Symfony\Component\ErrorHandler\DebugClassLoader; /** * Catch deprecation notices and print a summary report at the end of the test suite. @@ -178,6 +179,9 @@ public function shutdown() return; } + if (method_exists(DebugClassLoader::class, 'checkClasses')) { + DebugClassLoader::checkClasses(); + } $currErrorHandler = set_error_handler('var_dump'); restore_error_handler(); diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php index f93dd0baf9148..5c79a4d7f1b08 100644 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php @@ -10,7 +10,7 @@ */ // Please update when phpunit needs to be reinstalled with fresh deps: -// Cache-Id: 2019-08-09 13:00 UTC +// Cache-Id: 2019-09-02 16:00 UTC error_reporting(-1); diff --git a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php index 1f30cfa9f5ce4..67a6c1500baa4 100644 --- a/src/Symfony/Component/ErrorHandler/DebugClassLoader.php +++ b/src/Symfony/Component/ErrorHandler/DebugClassLoader.php @@ -11,7 +11,11 @@ namespace Symfony\Component\ErrorHandler; +use Doctrine\Common\Persistence\Proxy; use PHPUnit\Framework\MockObject\Matcher\StatelessInvocation; +use PHPUnit\Framework\MockObject\MockObject; +use Prophecy\Prophecy\ProphecySubjectInterface; +use ProxyManager\Proxy\ProxyInterface; /** * Autoloader checking if the class is really defined in the file found. @@ -230,22 +234,57 @@ public static function disable(): void spl_autoload_unregister($function); } + foreach ($functions as $function) { + if (\is_array($function) && $function[0] instanceof self) { + $function = $function[0]->getClassLoader(); + } + + spl_autoload_register($function); + } + } + + public static function checkClasses(): bool + { + if (!\is_array($functions = spl_autoload_functions())) { + return false; + } + $loader = null; foreach ($functions as $function) { if (\is_array($function) && $function[0] instanceof self) { $loader = $function[0]; - $function = $function[0]->getClassLoader(); + break; } + } - spl_autoload_register($function); + if (null === $loader) { + return false; } - if (null !== $loader) { - foreach (array_merge(get_declared_interfaces(), get_declared_traits(), get_declared_classes()) as $class) { - $loader->checkClass($class); + static $offsets = [ + 'get_declared_interfaces' => 0, + 'get_declared_traits' => 0, + 'get_declared_classes' => 0, + ]; + + foreach ($offsets as $getSymbols => $i) { + $symbols = $getSymbols(); + + for (; $i < \count($symbols); ++$i) { + if (!is_subclass_of($symbols[$i], MockObject::class) + && !is_subclass_of($symbols[$i], ProphecySubjectInterface::class) + && !is_subclass_of($symbols[$i], Proxy::class) + && !is_subclass_of($symbols[$i], ProxyInterface::class) + ) { + $loader->checkClass($symbols[$i]); + } } + + $offsets[$getSymbols] = $i; } + + return true; } public function findFile(string $class): ?string