Skip to content

Commit 4c41ad6

Browse files
Randy Geraadsnicolas-grekas
Randy Geraads
authored andcommitted
[DI] Fix Preloader exception when preloading a class with an unknown parent/interface
1 parent b296fd4 commit 4c41ad6

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Dumper/Preloader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private static function doPreload(string $class, array &$preloaded): void
8787

8888
self::preloadType($m->getReturnType(), $preloaded);
8989
}
90-
} catch (\ReflectionException $e) {
90+
} catch (\Throwable $e) {
9191
// ignore missing classes
9292
}
9393
}

Tests/Dumper/PreloaderTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ public function testPreload()
3434
self::assertTrue(class_exists('Symfony\Component\DependencyInjection\Tests\Fixtures\Preload\C', false));
3535
}
3636

37+
/**
38+
* @requires PHP 7.4
39+
*/
40+
public function testPreloadSkipsNonExistingInterface()
41+
{
42+
$r = new \ReflectionMethod(Preloader::class, 'doPreload');
43+
$r->setAccessible(true);
44+
45+
$preloaded = [];
46+
47+
$r->invokeArgs(null, ['Symfony\Component\DependencyInjection\Tests\Fixtures\Preload\DummyWithInterface', &$preloaded]);
48+
self::assertFalse(class_exists('Symfony\Component\DependencyInjection\Tests\Fixtures\Preload\DummyWithInterface', false));
49+
}
50+
3751
/**
3852
* @requires PHP 8
3953
*/
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Preload;
13+
14+
final class DummyWithInterface implements \NonExistentDummyInterface
15+
{
16+
}

0 commit comments

Comments
 (0)