Skip to content

Commit 0f01521

Browse files
authored
fix(symfony): 404 wrongly normalized (#5936)
fixes #5935
1 parent ad2cbe0 commit 0f01521

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

src/Hydra/Serializer/ErrorNormalizer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ public function supportsNormalization(mixed $data, string $format = null, array
7676
return false;
7777
}
7878

79-
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
79+
$decoration = $this->itemNormalizer ? $this->itemNormalizer->supportsNormalization($data, $format, $context) : true;
80+
81+
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException) && $decoration;
8082
}
8183

8284
public function getSupportedTypes($format): array

src/JsonApi/Serializer/ErrorNormalizer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public function supportsNormalization(mixed $data, string $format = null, array
7777
return false;
7878
}
7979

80-
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException);
80+
$decoration = $this->itemNormalizer ? $this->itemNormalizer->supportsNormalization($data, $format, $context) : true;
81+
82+
return self::FORMAT === $format && ($data instanceof \Exception || $data instanceof FlattenException) && $decoration;
8183
}
8284

8385
public function getSupportedTypes($format): array

src/Problem/Serializer/ErrorNormalizer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public function supportsNormalization(mixed $data, string $format = null, array
7575
return false;
7676
}
7777

78-
return (self::FORMAT === $format || 'json' === $format) && ($data instanceof \Exception || $data instanceof FlattenException);
78+
$decoration = $this->itemNormalizer ? $this->itemNormalizer->supportsNormalization($data, $format, $context) : true;
79+
80+
return (self::FORMAT === $format || 'json' === $format) && ($data instanceof \Exception || $data instanceof FlattenException) && $decoration;
7981
}
8082

8183
public function getSupportedTypes($format): array

tests/Symfony/Bundle/Test/ApiTestCaseTest.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,20 @@ public function testGetMercureMessages(): void
271271
);
272272
}
273273

274+
private function recreateSchema(array $options = []): void
275+
{
276+
self::bootKernel($options);
277+
278+
/** @var EntityManagerInterface $manager */
279+
$manager = static::getContainer()->get('doctrine')->getManager();
280+
/** @var ClassMetadata[] $classes */
281+
$classes = $manager->getMetadataFactory()->getAllMetadata();
282+
$schemaTool = new SchemaTool($manager);
283+
284+
@$schemaTool->dropSchema($classes);
285+
@$schemaTool->createSchema($classes);
286+
}
287+
274288
/**
275289
* @group legacy
276290
*/
@@ -289,17 +303,9 @@ public function testExceptionNormalizer(): void
289303
$this->assertEquals($data['hello'], 'world');
290304
}
291305

292-
private function recreateSchema(array $options = []): void
306+
public function testMissingMethod(): void
293307
{
294-
self::bootKernel($options);
295-
296-
/** @var EntityManagerInterface $manager */
297-
$manager = static::getContainer()->get('doctrine')->getManager();
298-
/** @var ClassMetadata[] $classes */
299-
$classes = $manager->getMetadataFactory()->getAllMetadata();
300-
$schemaTool = new SchemaTool($manager);
301-
302-
@$schemaTool->dropSchema($classes);
303-
@$schemaTool->createSchema($classes);
308+
$response = self::createClient([], ['headers' => ['accept' => 'application/json']])->request('DELETE', '/something/that/does/not/exist/ever');
309+
$this->assertResponseStatusCodeSame(404);
304310
}
305311
}

0 commit comments

Comments
 (0)