From 88d836643a4598a7ca6a43d845ccb12ced11c174 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 28 Apr 2020 19:42:54 +0200 Subject: [PATCH] provide a useful message when extension types don't match --- .../DependencyInjection/DependencyInjectionExtension.php | 4 ++-- .../DependencyInjection/DependencyInjectionExtensionTest.php | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php b/src/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php index e4314648df..7ed2f32171 100644 --- a/src/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php +++ b/src/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php @@ -53,7 +53,7 @@ class DependencyInjectionExtension implements FormExtensionInterface $extensions = []; if (isset($this->typeExtensionServices[$name])) { - foreach ($this->typeExtensionServices[$name] as $serviceId => $extension) { + foreach ($this->typeExtensionServices[$name] as $extension) { $extensions[] = $extension; if (method_exists($extension, 'getExtendedTypes')) { @@ -68,7 +68,7 @@ class DependencyInjectionExtension implements FormExtensionInterface // validate the result of getExtendedTypes()/getExtendedType() to ensure it is consistent with the service definition if (!\in_array($name, $extendedTypes, true)) { - throw new InvalidArgumentException(sprintf('The extended type specified for the service "%s" does not match the actual extended type. Expected "%s", given "%s".', $serviceId, $name, implode(', ', $extendedTypes))); + throw new InvalidArgumentException(sprintf('The extended type "%s" specified for the type extension class "%s" does not match any of the actual extended types (["%s"]).', $name, \get_class($extension), implode('", "', $extendedTypes))); } } } diff --git a/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php b/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php index 923ad8a38f..26db2d8cea 100644 --- a/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php @@ -44,6 +44,8 @@ class DependencyInjectionExtensionTest extends TestCase public function testThrowExceptionForInvalidExtendedType() { $this->expectException('Symfony\Component\Form\Exception\InvalidArgumentException'); + $this->expectExceptionMessage(sprintf('The extended type "unmatched" specified for the type extension class "%s" does not match any of the actual extended types (["test"]).', TestTypeExtension::class)); + $extensions = [ 'unmatched' => new \ArrayIterator([new TestTypeExtension()]), ];