Skip to content

Commit

Permalink
[DI] Fix Preloader exception when preloading a class with an unknown …
Browse files Browse the repository at this point in the history
…parent/interface
  • Loading branch information
Randy Geraads authored and nicolas-grekas committed Oct 27, 2020
1 parent b296fd4 commit 4c41ad6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dumper/Preloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static function doPreload(string $class, array &$preloaded): void

self::preloadType($m->getReturnType(), $preloaded);
}
} catch (\ReflectionException $e) {
} catch (\Throwable $e) {
// ignore missing classes
}
}
Expand Down
14 changes: 14 additions & 0 deletions Tests/Dumper/PreloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ public function testPreload()
self::assertTrue(class_exists('Symfony\Component\DependencyInjection\Tests\Fixtures\Preload\C', false));
}

/**
* @requires PHP 7.4
*/
public function testPreloadSkipsNonExistingInterface()
{
$r = new \ReflectionMethod(Preloader::class, 'doPreload');
$r->setAccessible(true);

$preloaded = [];

$r->invokeArgs(null, ['Symfony\Component\DependencyInjection\Tests\Fixtures\Preload\DummyWithInterface', &$preloaded]);
self::assertFalse(class_exists('Symfony\Component\DependencyInjection\Tests\Fixtures\Preload\DummyWithInterface', false));
}

/**
* @requires PHP 8
*/
Expand Down
16 changes: 16 additions & 0 deletions Tests/Fixtures/Preload/DummyWithInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Tests\Fixtures\Preload;

final class DummyWithInterface implements \NonExistentDummyInterface
{
}

0 comments on commit 4c41ad6

Please sign in to comment.