Skip to content

Commit 62f439b

Browse files
author
allison guilhem
committed
[Serializer] Add test if wrong backed enum
1 parent bd6440f commit 62f439b

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/Symfony/Component/Serializer/Tests/SerializerTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ public function testCollectDenormalizationErrorsWithEnumConstructor()
11891189
);
11901190

11911191
try {
1192-
$serializer->deserialize('{"invalid": "get"}', DummyObjectWithEnumConstructor::class, 'json', [
1192+
$serializer->deserialize('{"invalid": "GET"}', DummyObjectWithEnumConstructor::class, 'json', [
11931193
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
11941194
]);
11951195
} catch (\Throwable $th) {
@@ -1215,6 +1215,29 @@ public function testCollectDenormalizationErrorsWithEnumConstructor()
12151215
$this->assertSame($expected, $exceptionsAsArray);
12161216
}
12171217

1218+
/**
1219+
* @requires PHP 8.1
1220+
*/
1221+
public function testNoCollectDenormalizationErrorsWithWrongEnum()
1222+
{
1223+
$serializer = new Serializer(
1224+
[
1225+
new BackedEnumNormalizer(),
1226+
new ObjectNormalizer(),
1227+
],
1228+
['json' => new JsonEncoder()]
1229+
);
1230+
1231+
try {
1232+
$serializer->deserialize('{"get": "invalid"}', DummyObjectWithEnumConstructor::class, 'json', [
1233+
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
1234+
]);
1235+
} catch (\Throwable $th) {
1236+
$this->assertNotInstanceOf(PartialDenormalizationException::class, $th);
1237+
$this->assertInstanceOf(InvalidArgumentException::class, $th);
1238+
}
1239+
}
1240+
12181241
public function provideCollectDenormalizationErrors()
12191242
{
12201243
return [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy