diff --git a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php index e7ab1b8d7288..1ba8e7624832 100644 --- a/src/Symfony/Component/Config/Resource/ClassExistenceResource.php +++ b/src/Symfony/Component/Config/Resource/ClassExistenceResource.php @@ -155,7 +155,7 @@ public static function throwOnRequiredClass($class, \Exception $previous = null) throw $previous; } - $e = new \ReflectionException("Class $class not found", 0, $previous); + $e = new \ReflectionException(sprintf('Class "%s" not found while loading "%s".', $class, self::$autoloadedClass), 0, $previous); if (null !== $previous) { throw $e; diff --git a/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php b/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php index ad331240deba..b7ae81eaa6dd 100644 --- a/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php +++ b/src/Symfony/Component/Config/Tests/Resource/ClassExistenceResourceTest.php @@ -84,7 +84,7 @@ public function testBadParentWithTimestamp() public function testBadParentWithNoTimestamp() { $this->expectException('ReflectionException'); - $this->expectExceptionMessage('Class Symfony\Component\Config\Tests\Fixtures\MissingParent not found'); + $this->expectExceptionMessage('Class "Symfony\Component\Config\Tests\Fixtures\MissingParent" not found while loading "Symfony\Component\Config\Tests\Fixtures\BadParent".'); $res = new ClassExistenceResource(BadParent::class, false); $res->isFresh(0); diff --git a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php index 53873c15e625..f9bfcb52109d 100644 --- a/src/Symfony/Component/DependencyInjection/ContainerBuilder.php +++ b/src/Symfony/Component/DependencyInjection/ContainerBuilder.php @@ -361,7 +361,7 @@ public function getReflectionClass($class, $throw = true) return null; } - $resource = null; + $resource = $classReflector = null; try { if (isset($this->classReflectors[$class])) { @@ -376,7 +376,6 @@ public function getReflectionClass($class, $throw = true) if ($throw) { throw $e; } - $classReflector = false; } if ($this->trackResources) { diff --git a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php index 186c9c4cec7c..77cad3c046d7 100644 --- a/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php +++ b/src/Symfony/Component/DependencyInjection/Loader/FileLoader.php @@ -149,12 +149,7 @@ private function findClasses($namespace, $pattern, $excludePattern) try { $r = $this->container->getReflectionClass($class); } catch (\ReflectionException $e) { - $classes[$class] = sprintf( - 'While discovering services from namespace "%s", an error was thrown when processing the class "%s": "%s".', - $namespace, - $class, - $e->getMessage() - ); + $classes[$class] = $e->getMessage(); continue; } // check to make sure the expected class exists diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php index 7eb7f6024696..c5bcc660a5e4 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php @@ -380,7 +380,7 @@ public function testClassNotFoundThrowsException() public function testParentClassNotFoundThrowsException() { $this->expectException('Symfony\Component\DependencyInjection\Exception\AutowiringFailedException'); - $this->expectExceptionMessage('Cannot autowire service "a": argument "$r" of method "Symfony\Component\DependencyInjection\Tests\Compiler\BadParentTypeHintedArgument::__construct()" has type "Symfony\Component\DependencyInjection\Tests\Compiler\OptionalServiceClass" but this class is missing a parent class (Class Symfony\Bug\NotExistClass not found).'); + $this->expectExceptionMessageRegExp('{^Cannot autowire service "a": argument "\$r" of method "(Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Compiler\\\\)BadParentTypeHintedArgument::__construct\(\)" has type "\1OptionalServiceClass" but this class is missing a parent class \(Class "?Symfony\\\\Bug\\\\NotExistClass"? not found}'); $container = new ContainerBuilder(); diff --git a/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php b/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php index b6a816e40898..ffe58a67ef3b 100644 --- a/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php +++ b/src/Symfony/Component/DependencyInjection/Tests/Loader/FileLoaderTest.php @@ -178,9 +178,9 @@ public function testMissingParentClass() $this->assertTrue($container->has(MissingParent::class)); - $this->assertSame( - ['While discovering services from namespace "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\", an error was thrown when processing the class "Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingParent": "Class Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\MissingClass not found".'], - $container->getDefinition(MissingParent::class)->getErrors() + $this->assertRegExp( + '{Class "?Symfony\\\\Component\\\\DependencyInjection\\\\Tests\\\\Fixtures\\\\Prototype\\\\BadClasses\\\\MissingClass"? not found}', + $container->getDefinition(MissingParent::class)->getErrors()[0] ); }