Skip to content

Commit 700ff40

Browse files
Merge branch '6.4' into 7.0
* 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
2 parents aecccfb + 22301f0 commit 700ff40

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.4
5+
---
6+
7+
* Improve message with full path on invalid type in nested option
8+
49
6.3
510
---
611

OptionsResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
10641064
if (!$success) {
10651065
$message = sprintf(
10661066
'The option "%s" with value %s is invalid.',
1067-
$option,
1067+
$this->formatOptions([$option]),
10681068
$this->formatValue($value)
10691069
);
10701070

Tests/OptionsResolverTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,32 @@ public function testFailIfSetAllowedValuesFromLazyOption()
10091009
$this->resolver->resolve();
10101010
}
10111011

1012+
public function testResolveFailsIfInvalidValueFromNestedOption()
1013+
{
1014+
$this->expectException(InvalidOptionsException::class);
1015+
$this->expectExceptionMessage('The option "foo[bar]" with value "invalid value" is invalid. Accepted values are: "valid value".');
1016+
$this->resolver->setDefault('foo', function (OptionsResolver $resolver) {
1017+
$resolver
1018+
->setDefined('bar')
1019+
->setAllowedValues('bar', 'valid value');
1020+
});
1021+
1022+
$this->resolver->resolve(['foo' => ['bar' => 'invalid value']]);
1023+
}
1024+
1025+
public function testResolveFailsIfInvalidTypeFromNestedOption()
1026+
{
1027+
$this->expectException(InvalidOptionsException::class);
1028+
$this->expectExceptionMessage('The option "foo[bar]" with value 1 is expected to be of type "string", but is of type "int".');
1029+
$this->resolver->setDefault('foo', function (OptionsResolver $resolver) {
1030+
$resolver
1031+
->setDefined('bar')
1032+
->setAllowedTypes('bar', 'string');
1033+
});
1034+
1035+
$this->resolver->resolve(['foo' => ['bar' => 1]]);
1036+
}
1037+
10121038
public function testResolveFailsIfInvalidValue()
10131039
{
10141040
$this->expectException(InvalidOptionsException::class);

0 commit comments

Comments
 (0)