Skip to content

Commit faa6e52

Browse files
committed
provide a useful message when extension types don't match
1 parent 4cf3944 commit faa6e52

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Extension/DependencyInjection/DependencyInjectionExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getTypeExtensions($name)
5353
$extensions = [];
5454

5555
if (isset($this->typeExtensionServices[$name])) {
56-
foreach ($this->typeExtensionServices[$name] as $serviceId => $extension) {
56+
foreach ($this->typeExtensionServices[$name] as $extension) {
5757
$extensions[] = $extension;
5858

5959
if (method_exists($extension, 'getExtendedTypes')) {
@@ -68,7 +68,7 @@ public function getTypeExtensions($name)
6868

6969
// validate the result of getExtendedTypes()/getExtendedType() to ensure it is consistent with the service definition
7070
if (!\in_array($name, $extendedTypes, true)) {
71-
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)));
71+
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)));
7272
}
7373
}
7474
}

Tests/Extension/DependencyInjection/DependencyInjectionExtensionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public function testGetTypeExtensions()
4444
public function testThrowExceptionForInvalidExtendedType()
4545
{
4646
$this->expectException('Symfony\Component\Form\Exception\InvalidArgumentException');
47+
$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));
48+
4749
$extensions = [
4850
'unmatched' => new \ArrayIterator([new TestTypeExtension()]),
4951
];

0 commit comments

Comments
 (0)