Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/State/Provider/DeserializeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
$parameters = [];
if ($exception->canUseMessageForUser()) {
$parameters['hint'] = $exception->getMessage();
}
if (!$expectedTypes && $exception->canUseMessageForUser()) {
$violationMessage = $exception->getMessage();
$violations->add(new ConstraintViolation($violationMessage, $violationMessage, $parameters, null, $exception->getPath(), null, null, (string) Type::INVALID_TYPE_ERROR));
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/State/Tests/Provider/DeserializeProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function testDeserializeSetsObjectToPopulateWhenContextIsTrue(): void
}

#[IgnoreDeprecations]
public function testDeserializeUsesExceptionMessageWhenCanUseMessageForUser(): void
public function testDeserializeKeepsTypeMessageWhenExpectedTypesAreSet(): void
{
$operation = new Post(deserialize: true, class: \stdClass::class);
$decorated = $this->createStub(ProviderInterface::class);
Expand Down Expand Up @@ -239,10 +239,10 @@ public function testDeserializeUsesExceptionMessageWhenCanUseMessageForUser(): v
} catch (ValidationException $e) {
$violations = $e->getConstraintViolationList();
$this->assertCount(1, $violations);
$this->assertSame('The data must belong to a backed enumeration of type Suit.', $violations[0]->getMessage());
$this->assertSame('The data must belong to a backed enumeration of type Suit.', $violations[0]->getMessageTemplate());
$this->assertSame('This value should be of type string.', $violations[0]->getMessage());
$this->assertSame('status', $violations[0]->getPropertyPath());
$this->assertSame((string) Type::INVALID_TYPE_ERROR, $violations[0]->getCode());
$this->assertSame('The data must belong to a backed enumeration of type Suit.', $violations[0]->getParameters()['hint'] ?? null);
}
}

Expand Down
8 changes: 5 additions & 3 deletions tests/Functional/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function testPostWithDenormalizationErrorsCollected(): void

$violationBaz = $findViolation('baz');
$this->assertNotNull($violationBaz, 'Violation for "baz" not found.');
$this->assertSame('Failed to create object because the class misses the "baz" property.', $violationBaz['message']);
$this->assertSame('This value should be of type string.', $violationBaz['message']);
$this->assertArrayHasKey('hint', $violationBaz);
$this->assertSame('Failed to create object because the class misses the "baz" property.', $violationBaz['hint']);

Expand Down Expand Up @@ -117,14 +117,16 @@ public function testPostWithDenormalizationErrorsCollected(): void
$violationUuid = $findViolation('uuid');
$this->assertNotNull($violationUuid);
if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
$this->assertSame('Invalid UUID string: y', $violationUuid['message']);
$this->assertSame('This value should be of type uuid.', $violationUuid['message']);
} else {
$this->assertSame('This value should be of type UuidInterface|null.', $violationUuid['message']);
}

$violationRelatedDummy = $findViolation('relatedDummy');
$this->assertNotNull($violationRelatedDummy);
$this->assertSame('The type of the "relatedDummy" attribute must be "array" (nested document) or "string" (IRI), "integer" given.', $violationRelatedDummy['message']);
$this->assertSame('This value should be of type array|string.', $violationRelatedDummy['message']);
$this->assertArrayHasKey('hint', $violationRelatedDummy);
$this->assertSame('The type of the "relatedDummy" attribute must be "array" (nested document) or "string" (IRI), "integer" given.', $violationRelatedDummy['hint']);

$violationRelatedDummies = $findViolation('relatedDummies');
$this->assertNotNull($violationRelatedDummies);
Expand Down
Loading