Skip to content

Commit a1a914e

Browse files
bug #33430 [ErrorHandler][Bridge/PhpUnit] display deprecations for not-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
2 parents bb3652a + 2ba3cc0 commit a1a914e

File tree

3 files changed

+49
-6
lines changed

3 files changed

+49
-6
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Util\ErrorHandler;
1616
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Configuration;
1717
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
18+
use Symfony\Component\ErrorHandler\DebugClassLoader;
1819

1920
/**
2021
* Catch deprecation notices and print a summary report at the end of the test suite.
@@ -178,6 +179,9 @@ public function shutdown()
178179
return;
179180
}
180181

182+
if (method_exists(DebugClassLoader::class, 'checkClasses')) {
183+
DebugClassLoader::checkClasses();
184+
}
181185
$currErrorHandler = set_error_handler('var_dump');
182186
restore_error_handler();
183187

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
// Please update when phpunit needs to be reinstalled with fresh deps:
13-
// Cache-Id: 2019-08-09 13:00 UTC
13+
// Cache-Id: 2019-09-02 16:00 UTC
1414

1515
error_reporting(-1);
1616

src/Symfony/Component/ErrorHandler/DebugClassLoader.php

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
namespace Symfony\Component\ErrorHandler;
1313

14+
use Doctrine\Common\Persistence\Proxy;
1415
use PHPUnit\Framework\MockObject\Matcher\StatelessInvocation;
16+
use PHPUnit\Framework\MockObject\MockObject;
17+
use Prophecy\Prophecy\ProphecySubjectInterface;
18+
use ProxyManager\Proxy\ProxyInterface;
1519

1620
/**
1721
* Autoloader checking if the class is really defined in the file found.
@@ -230,22 +234,57 @@ public static function disable(): void
230234
spl_autoload_unregister($function);
231235
}
232236

237+
foreach ($functions as $function) {
238+
if (\is_array($function) && $function[0] instanceof self) {
239+
$function = $function[0]->getClassLoader();
240+
}
241+
242+
spl_autoload_register($function);
243+
}
244+
}
245+
246+
public static function checkClasses(): bool
247+
{
248+
if (!\is_array($functions = spl_autoload_functions())) {
249+
return false;
250+
}
251+
233252
$loader = null;
234253

235254
foreach ($functions as $function) {
236255
if (\is_array($function) && $function[0] instanceof self) {
237256
$loader = $function[0];
238-
$function = $function[0]->getClassLoader();
257+
break;
239258
}
259+
}
240260

241-
spl_autoload_register($function);
261+
if (null === $loader) {
262+
return false;
242263
}
243264

244-
if (null !== $loader) {
245-
foreach (array_merge(get_declared_interfaces(), get_declared_traits(), get_declared_classes()) as $class) {
246-
$loader->checkClass($class);
265+
static $offsets = [
266+
'get_declared_interfaces' => 0,
267+
'get_declared_traits' => 0,
268+
'get_declared_classes' => 0,
269+
];
270+
271+
foreach ($offsets as $getSymbols => $i) {
272+
$symbols = $getSymbols();
273+
274+
for (; $i < \count($symbols); ++$i) {
275+
if (!is_subclass_of($symbols[$i], MockObject::class)
276+
&& !is_subclass_of($symbols[$i], ProphecySubjectInterface::class)
277+
&& !is_subclass_of($symbols[$i], Proxy::class)
278+
&& !is_subclass_of($symbols[$i], ProxyInterface::class)
279+
) {
280+
$loader->checkClass($symbols[$i]);
281+
}
247282
}
283+
284+
$offsets[$getSymbols] = $i;
248285
}
286+
287+
return true;
249288
}
250289

251290
public function findFile(string $class): ?string

0 commit comments

Comments
 (0)