Skip to content

[ErrorHandler][Bridge/PhpUnit] display deprecations for not-autoloaded classes #33430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
49 changes: 44 additions & 5 deletions src/Symfony/Component/ErrorHandler/DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down