Skip to content

Commit

Permalink
minor #36613 [Form] provide a useful message when extension types don…
Browse files Browse the repository at this point in the history
…'t match (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Form] provide a useful message when extension types don't match

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36610
| License       | MIT
| Doc PR        |

Commits
-------

88d8366 provide a useful message when extension types don't match
  • Loading branch information
xabbuh committed May 2, 2020
2 parents 4528c11 + 88d8366 commit a804333
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Expand Up @@ -53,7 +53,7 @@ public function getTypeExtensions($name)
$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')) {
Expand All @@ -68,7 +68,7 @@ public function getTypeExtensions($name)

// 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)));
}
}
}
Expand Down
Expand Up @@ -44,6 +44,8 @@ public function testGetTypeExtensions()
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()]),
];
Expand Down

0 comments on commit a804333

Please sign in to comment.