Skip to content

Commit

Permalink
Merge branch '6.4' into 7.0
Browse files Browse the repository at this point in the history
* 6.4:
  [OptionsResolver] Improve invalid type message on nested option
  cs fix
  Update KernelTestCase.php
  [DoctrineBridge] Silence ORM deprecation
  add missing default-doctrine-dbal-provider cache pool attribute to XSD
  • Loading branch information
nicolas-grekas committed Aug 8, 2023
2 parents aecccfb + 22301f0 commit 700ff40
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

6.4
---

* Improve message with full path on invalid type in nested option

6.3
---

Expand Down
2 changes: 1 addition & 1 deletion OptionsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
if (!$success) {
$message = sprintf(
'The option "%s" with value %s is invalid.',
$option,
$this->formatOptions([$option]),
$this->formatValue($value)
);

Expand Down
26 changes: 26 additions & 0 deletions Tests/OptionsResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,32 @@ public function testFailIfSetAllowedValuesFromLazyOption()
$this->resolver->resolve();
}

public function testResolveFailsIfInvalidValueFromNestedOption()
{
$this->expectException(InvalidOptionsException::class);
$this->expectExceptionMessage('The option "foo[bar]" with value "invalid value" is invalid. Accepted values are: "valid value".');
$this->resolver->setDefault('foo', function (OptionsResolver $resolver) {
$resolver
->setDefined('bar')
->setAllowedValues('bar', 'valid value');
});

$this->resolver->resolve(['foo' => ['bar' => 'invalid value']]);
}

public function testResolveFailsIfInvalidTypeFromNestedOption()
{
$this->expectException(InvalidOptionsException::class);
$this->expectExceptionMessage('The option "foo[bar]" with value 1 is expected to be of type "string", but is of type "int".');
$this->resolver->setDefault('foo', function (OptionsResolver $resolver) {
$resolver
->setDefined('bar')
->setAllowedTypes('bar', 'string');
});

$this->resolver->resolve(['foo' => ['bar' => 1]]);
}

public function testResolveFailsIfInvalidValue()
{
$this->expectException(InvalidOptionsException::class);
Expand Down

0 comments on commit 700ff40

Please sign in to comment.