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

Skip to content

Commit 4fefa38

Browse files
author
allison guilhem
committed
[Serializer] tryfrom to tryFrom - assignments inlined - newLine + add backedEnum type in message
1 parent 35ce82a commit 4fefa38

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/Symfony/Component/Serializer/Normalizer/BackedEnumNormalizer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ public function denormalize($data, $type, $format = null, array $context = [])
6161
throw NotNormalizableValueException::createForUnexpectedDataType('The data is neither an integer nor a string, you should pass an integer or a string that can be parsed as an enumeration case of type '.$type.'.', $data, [Type::BUILTIN_TYPE_INT, Type::BUILTIN_TYPE_STRING], $context['deserialization_path'] ?? null, true);
6262
}
6363

64-
$matched = $type::tryfrom($data);
65-
if (!$matched) {
66-
throw new InvalidArgumentException('The data must belong to a backed enumeration.');
64+
if (!$matched = $type::tryFrom($data)) {
65+
throw new InvalidArgumentException('The data must belong to a backed enumeration of type ' . $type);
6766
}
6867

6968
return $matched;

src/Symfony/Component/Serializer/Tests/Fixtures/DummyObjectWithEnumConstructor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class DummyObjectWithEnumConstructor
88
{
9-
public function __construct(public StringBackedEnumDummy $get)
9+
public function __construct(public StringBackedEnumDummy $get)
1010
{
1111
}
12-
}
12+
}

src/Symfony/Component/Serializer/Tests/Normalizer/BackedEnumNormalizerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public function testDenormalizeObjectThrowsException()
116116
public function testDenormalizeBadBackingValueThrowsException()
117117
{
118118
$this->expectException(InvalidArgumentException::class);
119+
$this->expectExceptionMessage('The data must belong to a backed enumeration of type ' . StringBackedEnumDummy::class);
120+
119121
$this->normalizer->denormalize('POST', StringBackedEnumDummy::class);
120122
}
121123

0 commit comments

Comments
 (0)