Skip to content

Commit 49093e5

Browse files
IndraGunawanchalasr
authored andcommitted
[Serializer] Fixed BackedEnumNormalizer priority for translatable enum
1 parent 044c21b commit 49093e5

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

Resources/config/serializer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,6 @@
219219
])
220220

221221
->set('serializer.normalizer.backed_enum', BackedEnumNormalizer::class)
222-
->tag('serializer.normalizer', ['priority' => -915])
222+
->tag('serializer.normalizer', ['priority' => -880])
223223
;
224224
};
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;
13+
14+
use Symfony\Contracts\Translation\TranslatableInterface;
15+
use Symfony\Contracts\Translation\TranslatorInterface;
16+
17+
enum TranslatableBackedEnum: string implements TranslatableInterface
18+
{
19+
case Get = 'GET';
20+
21+
public function trans(TranslatorInterface $translator, ?string $locale = null): string
22+
{
23+
return match ($this) {
24+
self::Get => 'custom_get_string',
25+
};
26+
}
27+
}

Tests/Functional/SerializerTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;
1313

14+
use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\TranslatableBackedEnum;
15+
1416
/**
1517
* @author Kévin Dunglas <[email protected]>
1618
*/
@@ -67,6 +69,15 @@ public static function provideNormalizersAndEncodersWithDefaultContextOption():
6769
['serializer.encoder.csv.alias'],
6870
];
6971
}
72+
73+
public function testSerializeTranslatableBackedEnum()
74+
{
75+
static::bootKernel(['test_case' => 'Serializer']);
76+
77+
$serializer = static::getContainer()->get('serializer.alias');
78+
79+
$this->assertEquals('GET', $serializer->serialize(TranslatableBackedEnum::Get, 'yaml'));
80+
}
7081
}
7182

7283
class Foo

0 commit comments

Comments
 (0)