Skip to content

Commit 454262b

Browse files
authored
fix(symfony): avoid deprecated translation command probe (#8627)
1 parent 206a0ff commit 454262b

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
use PHPStan\PhpDocParser\Parser\PhpDocParser;
7171
use Ramsey\Uuid\Uuid;
7272
use Symfony\AI\McpBundle\McpBundle;
73-
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand;
73+
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand as FrameworkTranslationExtractCommand;
7474
use Symfony\Bundle\FrameworkBundle\Controller\ControllerHelper;
7575
use Symfony\Component\Config\FileLocator;
7676
use Symfony\Component\Config\Resource\DirectoryResource;
@@ -89,6 +89,7 @@
8989
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
9090
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
9191
use Symfony\Component\Serializer\Normalizer\NumberNormalizer;
92+
use Symfony\Component\Translation\Command\TranslationExtractCommand;
9293
use Symfony\Component\Uid\AbstractUid;
9394
use Symfony\Component\Validator\Validator\ValidatorInterface;
9495
use Symfony\Component\Yaml\Yaml;
@@ -212,7 +213,7 @@ public function load(array $configs, ContainerBuilder $container): void
212213
// TranslationExtractCommand was introduced in framework-bundle/7.3 with the object mapper service.
213214
// willBeAvailable mirrors FrameworkBundle's own gate: when symfony/object-mapper is in dev-only,
214215
// FrameworkBundle skips object_mapper.php and the "object_mapper" service we alias to does not exist.
215-
if (class_exists(ObjectMapper::class) && class_exists(TranslationExtractCommand::class) && ContainerBuilder::willBeAvailable('symfony/object-mapper', ObjectMapperInterface::class, ['symfony/framework-bundle'])) {
216+
if (class_exists(ObjectMapper::class) && (class_exists(TranslationExtractCommand::class) || class_exists(FrameworkTranslationExtractCommand::class)) && ContainerBuilder::willBeAvailable('symfony/object-mapper', ObjectMapperInterface::class, ['symfony/framework-bundle'])) {
216217
$loader->load('state/object_mapper.php');
217218
$loader->load($config['use_symfony_listeners'] ? 'symfony/object_mapper.php' : 'state/object_mapper_processor.php');
218219
}

‎src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@
2929
use ApiPlatform\Tests\Fixtures\TestBundle\TestBundle;
3030
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
3131
use Doctrine\ORM\OptimisticLockException;
32+
use PHPUnit\Framework\Attributes\PreserveGlobalState;
33+
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
3234
use PHPUnit\Framework\TestCase;
3335
use Symfony\AI\McpBundle\McpBundle;
36+
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand as FrameworkTranslationExtractCommand;
3437
use Symfony\Bundle\SecurityBundle\SecurityBundle;
3538
use Symfony\Bundle\TwigBundle\TwigBundle;
3639
use Symfony\Component\DependencyInjection\ChildDefinition;
3740
use Symfony\Component\DependencyInjection\ContainerBuilder;
3841
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
3942
use Symfony\Component\HttpFoundation\Response;
4043
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
44+
use Symfony\Component\Translation\Command\TranslationExtractCommand;
4145

4246
class ApiPlatformExtensionTest extends TestCase
4347
{
@@ -184,6 +188,20 @@ private function assertServiceHasTags(string $service, array $tags = []): void
184188
}
185189
}
186190

191+
#[RunInSeparateProcess]
192+
#[PreserveGlobalState(false)]
193+
public function testObjectMapperDoesNotLoadDeprecatedTranslationCommand(): void
194+
{
195+
if (!class_exists(TranslationExtractCommand::class)) {
196+
self::markTestSkipped('Requires the Symfony 8.2 translation command.');
197+
}
198+
199+
(new ApiPlatformExtension())->load(self::DEFAULT_CONFIG, $this->container);
200+
201+
self::assertTrue($this->container->hasDefinition('api_platform.object_mapper.metadata_factory'));
202+
self::assertFalse(class_exists(FrameworkTranslationExtractCommand::class, false));
203+
}
204+
187205
public function testCommonConfiguration(): void
188206
{
189207
$config = self::DEFAULT_CONFIG;

0 commit comments

Comments
 (0)