Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,17 @@ public static function mapQueryStringProvider(): iterable
"type": "https:\/\/symfony.com\/errors\/validation",
"title": "Validation Failed",
"status": 404,
"detail": "filter: This value should be of type Symfony\\Bundle\\FrameworkBundle\\Tests\\Functional\\Filter.",
"detail": "filter: The value for argument \"filter\" should be of type Symfony\\Bundle\\FrameworkBundle\\Tests\\Functional\\Filter.",
Copy link
Copy Markdown
Member

@nicolas-grekas nicolas-grekas May 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now seeing the failures on high-deps, which is when FWK 8.0 will run with HK 8.1

And then I realize: "filter: [...]" - this is already the arguments name.
and in the list of violations, we have "propertyPath": "filter"

which means: do we have anything to fix? if yes should we just add the path param for translations and keep the existing message?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or should we clean the "detail" prefix ;) )

Copy link
Copy Markdown
Member Author

@HypeMC HypeMC May 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicolas-grekas The "filter: [...]" part is added by the ProblemNormalizer, meaning it's only shown when the normalizer is used. However, when the normalizer is not used, this information is not available. It's also not available in the logs.

As for the FWK 8.0 with HK 8.1 part, I'll fix this on lower branches.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or should we clean the "detail" prefix ;) )

Yes, i think that would make sense now.

"violations": [
{
"parameters": {
"hint": "Failed to create object because the class misses the \"filter\" property.",
"{{ path }}": "filter",
"{{ type }}": "Symfony\\Bundle\\FrameworkBundle\\Tests\\Functional\\Filter"
},
"propertyPath": "filter",
"template": "This value should be of type {{ type }}.",
"title": "This value should be of type Symfony\\Bundle\\FrameworkBundle\\Tests\\Functional\\Filter."
"template": "The value for argument \"{{ path }}\" should be of type {{ type }}.",
"title": "The value for argument \"filter\" should be of type Symfony\\Bundle\\FrameworkBundle\\Tests\\Functional\\Filter."
}
]
}
Expand Down Expand Up @@ -373,13 +374,14 @@ public static function mapRequestPayloadProvider(): iterable
"type": "https:\/\/symfony.com\/errors\/validation",
"title": "Validation Failed",
"status": 422,
"detail": "approved: This value should be of type bool.",
"detail": "approved: The value for argument \"approved\" should be of type bool.",
"violations": [
{
"propertyPath": "approved",
"title": "This value should be of type bool.",
"template": "This value should be of type {{ type }}.",
"title": "The value for argument \"approved\" should be of type bool.",
"template": "The value for argument \"{{ path }}\" should be of type {{ type }}.",
"parameters": {
"{{ path }}": "approved",
"{{ type }}": "bool"
}
}
Expand Down Expand Up @@ -600,7 +602,7 @@ public static function mapRequestPayloadProvider(): iterable
self::assertSame('https://symfony.com/errors/validation', $json['type'] ?? null);
self::assertSame('Validation Failed', $json['title'] ?? null);
self::assertSame(422, $json['status'] ?? null);
self::assertSame('approved: This value should be of type bool.', $json['detail'] ?? null);
self::assertSame('approved: The value for argument "approved" should be of type bool.', $json['detail'] ?? null);
self::assertIsArray($json['violations'] ?? null);
self::assertCount(1, $json['violations']);
self::assertSame('approved', $json['violations'][0]['propertyPath'] ?? null);
Expand Down Expand Up @@ -818,7 +820,7 @@ public static function mapRequestPayloadProvider(): iterable
self::assertSame('https://symfony.com/errors/validation', $json['type'] ?? null);
self::assertSame('Validation Failed', $json['title'] ?? null);
self::assertSame(422, $json['status'] ?? null);
self::assertSame('approved: This value should be of type bool.', $json['detail'] ?? null);
self::assertSame('approved: The value for argument "approved" should be of type bool.', $json['detail'] ?? null);
self::assertIsArray($json['violations'] ?? null);
self::assertCount(1, $json['violations']);
self::assertSame('approved', $json['violations'][0]['propertyPath'] ?? null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,17 @@ public function onKernelControllerArguments(ControllerArgumentsEvent $event): vo
$errors = method_exists($e, 'getNotNormalizableValueErrors') ? $e->getNotNormalizableValueErrors() : $e->getErrors();
foreach ($errors as $error) {
$parameters = [];
$template = 'This value was of an unexpected type.';
if ($path = $error->getPath()) {
$template = 'The value for argument "{{ path }}"';
$parameters['{{ path }}'] = $path;
} else {
$template = 'This value';
}
if ($expectedTypes = $error->getExpectedTypes()) {
$template = 'This value should be of type {{ type }}.';
$template .= ' should be of type {{ type }}.';
$parameters['{{ type }}'] = implode('|', $expectedTypes);
} else {
$template .= ' was of an unexpected type.';
}
if ($error->canUseMessageForUser()) {
$parameters['hint'] = $error->getMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function testValidationNotPassed()
$validationFailedException = $e->getPrevious();
$this->assertSame(422, $e->getStatusCode());
$this->assertInstanceOf(ValidationFailedException::class, $validationFailedException);
$this->assertSame('This value should be of type string.', $validationFailedException->getViolations()[0]->getMessage());
$this->assertSame('The value for argument "title" should be of type string.', $validationFailedException->getViolations()[0]->getMessage());
}
}

Expand Down Expand Up @@ -360,7 +360,7 @@ public function testValidationFailedOnInvalidBackedEnum()
$this->assertSame(422, $e->getStatusCode());
$this->assertInstanceOf(ValidationFailedException::class, $validationFailedException);
$this->assertContains($validationFailedException->getViolations()[0]->getMessage(), [
'This value was of an unexpected type.',
'The value for argument "method" was of an unexpected type.',
'This value should be of type int|string.',
'The data must belong to a backed enumeration of type Symfony\\Component\\HttpKernel\\Tests\\Controller\\ArgumentResolver\\RequestMethod',
]);
Expand Down Expand Up @@ -393,7 +393,7 @@ public function testValidationNotPerformedWhenPartialDenormalizationReturnsViola
} catch (HttpException $e) {
$validationFailedException = $e->getPrevious();
$this->assertInstanceOf(ValidationFailedException::class, $validationFailedException);
$this->assertSame('This value should be of type string.', $validationFailedException->getViolations()[0]->getMessage());
$this->assertSame('The value for argument "email" should be of type string.', $validationFailedException->getViolations()[0]->getMessage());
}
}

Expand Down Expand Up @@ -447,18 +447,17 @@ public function testRequestContentValidationPassed()
$this->assertEquals([$payload], $event->getArguments());
}

#[TestWith([null])]
#[TestWith([[]])]
public function testRequestContentWithUntypedErrors(?array $types)
#[TestWith([null, null, 'This value was of an unexpected type.'])]
#[TestWith([[], null, 'This value was of an unexpected type.'])]
#[TestWith([[], 'title', 'The value for argument "title" was of an unexpected type.'])]
public function testRequestContentWithUntypedErrors(?array $types, ?string $path, string $expectedMessage)
{
$this->expectException(HttpException::class);
$this->expectExceptionMessage('This value was of an unexpected type.');
$serializer = $this->createStub(SerializerDenormalizer::class);

if (null === $types) {
$exception = new NotNormalizableValueException('Error with no types');
} else {
$exception = NotNormalizableValueException::createForUnexpectedDataType('Error with no types', '', []);
$exception = NotNormalizableValueException::createForUnexpectedDataType('Error with no types', '', [], $path);
}
$serializer->method('deserialize')->willThrowException(new PartialDenormalizationException([], [$exception]));

Expand All @@ -470,6 +469,8 @@ public function testRequestContentWithUntypedErrors(?array $types)
]));
$event = new ControllerArgumentsEvent($this->createStub(HttpKernelInterface::class), static function () {}, $arguments, $request, HttpKernelInterface::MAIN_REQUEST);

$this->expectException(HttpException::class);
$this->expectExceptionMessage($expectedMessage);
$resolver->onKernelControllerArguments($event);
}

Expand Down Expand Up @@ -529,7 +530,7 @@ public function testQueryStringParameterTypeMismatch()
} catch (HttpException $e) {
$validationFailedException = $e->getPrevious();
$this->assertInstanceOf(ValidationFailedException::class, $validationFailedException);
$this->assertSame('This value should be of type float.', $validationFailedException->getViolations()[0]->getMessage());
$this->assertSame('The value for argument "price" should be of type float.', $validationFailedException->getViolations()[0]->getMessage());
}
}

Expand Down Expand Up @@ -623,7 +624,7 @@ public function testRequestInputTypeMismatch()
} catch (HttpException $e) {
$validationFailedException = $e->getPrevious();
$this->assertInstanceOf(ValidationFailedException::class, $validationFailedException);
$this->assertSame('This value should be of type float.', $validationFailedException->getViolations()[0]->getMessage());
$this->assertSame('The value for argument "price" should be of type float.', $validationFailedException->getViolations()[0]->getMessage());
}
}

Expand Down Expand Up @@ -951,7 +952,7 @@ public function testRequestPayloadValidationErrorCustomStatusCode()
$validationFailedException = $e->getPrevious();
$this->assertSame(400, $e->getStatusCode());
$this->assertInstanceOf(ValidationFailedException::class, $validationFailedException);
$this->assertSame('This value should be of type string.', $validationFailedException->getViolations()[0]->getMessage());
$this->assertSame('The value for argument "title" should be of type string.', $validationFailedException->getViolations()[0]->getMessage());
}
}

Expand Down
Loading