Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Serializer] Fixed BackedEnumNormalizer priority for translatable enum #54315

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,6 @@
])

->set('serializer.normalizer.backed_enum', BackedEnumNormalizer::class)
->tag('serializer.normalizer', ['priority' => -915])
->tag('serializer.normalizer', ['priority' => -880])
IndraGunawan marked this conversation as resolved.
Show resolved Hide resolved
;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\Fixtures;

use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

enum TranslatableBackedEnum: string implements TranslatableInterface
{
case Get = 'GET';

public function trans(TranslatorInterface $translator, ?string $locale = null): string
{
return match ($this) {
self::Get => 'custom_get_string',
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Bundle\FrameworkBundle\Tests\Functional;

use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\TranslatableBackedEnum;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
*/
Expand Down Expand Up @@ -67,6 +69,15 @@ public static function provideNormalizersAndEncodersWithDefaultContextOption():
['serializer.encoder.csv.alias'],
];
}

public function testSerializeTranslatableBackedEnum()
{
static::bootKernel(['test_case' => 'Serializer']);

$serializer = static::getContainer()->get('serializer.alias');

$this->assertEquals('GET', $serializer->serialize(TranslatableBackedEnum::Get, 'yaml'));
}
}

class Foo
Expand Down