Skip to content

Commit

Permalink
bug #33430 [ErrorHandler][Bridge/PhpUnit] display deprecations for no…
Browse files Browse the repository at this point in the history
…t-autoloaded classes (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Commits
-------

2ba3cc0 [ErrorHandler][Bridge/PhpUnit] display deprecations for not-autoloaded classes
  • Loading branch information
nicolas-grekas committed Sep 3, 2019
2 parents bb3652a + 2ba3cc0 commit a1a914e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
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
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
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

0 comments on commit a1a914e

Please sign in to comment.