Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 49093e5

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

File tree

Expand file treeCollapse file tree

3 files changed

+39
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+39
-1
lines changed

‎Resources/config/serializer.php

Copy file name to clipboardExpand all lines: Resources/config/serializer.php
+1-1Lines changed: 1 addition & 1 deletion
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
};
+27Lines changed: 27 additions & 0 deletions
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 <fabien@symfony.com>
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

Copy file name to clipboardExpand all lines: Tests/Functional/SerializerTest.php
+11Lines changed: 11 additions & 0 deletions
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 <dunglas@gmail.com>
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.