Skip to content

Commit 4216604

Browse files
Amrouche Hamzadunglas
authored andcommitted
hotfix: fix #549 throw an 404 error instead of 500
1 parent dc227ec commit 4216604

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

features/relation.feature

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,15 @@ Feature: Relations support
249249
}
250250
"""
251251

252-
@wip
253252
Scenario: Create an existing relation
254253
When I send a "POST" request to "/relation_embedders" with body:
255254
"""
256-
{
257-
"anotherRelated": {
258-
"symfony": "laravel"
259-
}
255+
{
256+
"anotherRelated": {
257+
"symfony": "laravel"
260258
}
261-
"""
259+
}
260+
"""
262261
Then the response status code should be 201
263262
And the response should be in JSON
264263
And the header "Content-Type" should be equal to "application/ld+json"
@@ -279,16 +278,31 @@ Feature: Relations support
279278
}
280279
"""
281280

281+
Scenario: Post a wrong relation
282+
When I send a "POST" request to "/relation_embedders" with body:
283+
"""
284+
{
285+
"anotherRelated": {
286+
"@id": "/related_dummies/123",
287+
"@type": "https://schema.org/Product",
288+
"symfony": "phalcon"
289+
}
290+
}
291+
"""
292+
Then the response status code should be 400
293+
And the response should be in JSON
294+
And the header "Content-Type" should be equal to "application/ld+json"
295+
282296
Scenario: Update an embedded relation
283297
When I send a "PUT" request to "/relation_embedders/2" with body:
284298
"""
285-
{
286-
"anotherRelated": {
287-
"@id": "/related_dummies/2",
288-
"symfony": "API Platform"
289-
}
299+
{
300+
"anotherRelated": {
301+
"@id": "/related_dummies/2",
302+
"symfony": "API Platform"
290303
}
291-
"""
304+
}
305+
"""
292306
Then the response status code should be 200
293307
And the response should be in JSON
294308
And the header "Content-Type" should be equal to "application/ld+json"
@@ -313,14 +327,14 @@ Feature: Relations support
313327
Scenario: Update an existing relation
314328
When I send a "POST" request to "/relation_embedders" with body:
315329
"""
316-
{
317-
"anotherRelated": {
318-
"@id": "/related_dummies/2",
319-
"@type": "https://schema.org/Product",
320-
"symfony": "phalcon"
321-
}
330+
{
331+
"anotherRelated": {
332+
"@id": "/related_dummies/2",
333+
"@type": "https://schema.org/Product",
334+
"symfony": "phalcon"
322335
}
323-
"""
336+
}
337+
"""
324338
Then the response status code should be 201
325339
And the response should be in JSON
326340
And the header "Content-Type" should be equal to "application/ld+json"

src/JsonLd/Serializer/ItemNormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function denormalize($data, $class, $format = null, array $context = [])
125125
$overrideClass = isset($data['@id']) && !isset($context['object_to_populate']);
126126

127127
if ($overrideClass) {
128-
$context['object_to_populate'] = $this->iriConverter->getItemFromIri($data['@id']);
128+
$context['object_to_populate'] = $this->iriConverter->getItemFromIri($data['@id'], true);
129129
}
130130

131131
return parent::denormalize($data, $class, $format, $context);
@@ -295,7 +295,7 @@ private function denormalizeRelation(string $resourceClass, string $attributeNam
295295
{
296296
if (is_string($value)) {
297297
try {
298-
return $this->iriConverter->getItemFromIri($value);
298+
return $this->iriConverter->getItemFromIri($value, true);
299299
} catch (InvalidArgumentException $e) {
300300
// Give a chance to other normalizers (e.g.: DateTimeNormalizer)
301301
}

0 commit comments

Comments
 (0)