Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use Ramsey\Uuid\Uuid;
use Symfony\AI\McpBundle\McpBundle;
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand;
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand as FrameworkTranslationExtractCommand;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerHelper;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\DirectoryResource;
Expand All @@ -89,6 +89,7 @@
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
use Symfony\Component\Serializer\Normalizer\NumberNormalizer;
use Symfony\Component\Translation\Command\TranslationExtractCommand;
use Symfony\Component\Uid\AbstractUid;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Yaml\Yaml;
Expand Down Expand Up @@ -212,7 +213,7 @@ public function load(array $configs, ContainerBuilder $container): void
// TranslationExtractCommand was introduced in framework-bundle/7.3 with the object mapper service.
// willBeAvailable mirrors FrameworkBundle's own gate: when symfony/object-mapper is in dev-only,
// FrameworkBundle skips object_mapper.php and the "object_mapper" service we alias to does not exist.
if (class_exists(ObjectMapper::class) && class_exists(TranslationExtractCommand::class) && ContainerBuilder::willBeAvailable('symfony/object-mapper', ObjectMapperInterface::class, ['symfony/framework-bundle'])) {
if (class_exists(ObjectMapper::class) && (class_exists(TranslationExtractCommand::class) || class_exists(FrameworkTranslationExtractCommand::class)) && ContainerBuilder::willBeAvailable('symfony/object-mapper', ObjectMapperInterface::class, ['symfony/framework-bundle'])) {
$loader->load('state/object_mapper.php');
$loader->load($config['use_symfony_listeners'] ? 'symfony/object_mapper.php' : 'state/object_mapper_processor.php');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@
use ApiPlatform\Tests\Fixtures\TestBundle\TestBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\ORM\OptimisticLockException;
use PHPUnit\Framework\Attributes\PreserveGlobalState;
use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use PHPUnit\Framework\TestCase;
use Symfony\AI\McpBundle\McpBundle;
use Symfony\Bundle\FrameworkBundle\Command\TranslationExtractCommand as FrameworkTranslationExtractCommand;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
use Symfony\Component\Translation\Command\TranslationExtractCommand;

class ApiPlatformExtensionTest extends TestCase
{
Expand Down Expand Up @@ -184,6 +188,20 @@ private function assertServiceHasTags(string $service, array $tags = []): void
}
}

#[RunInSeparateProcess]
#[PreserveGlobalState(false)]
public function testObjectMapperDoesNotLoadDeprecatedTranslationCommand(): void
{
if (!class_exists(TranslationExtractCommand::class)) {
self::markTestSkipped('Requires the Symfony 8.2 translation command.');
}

(new ApiPlatformExtension())->load(self::DEFAULT_CONFIG, $this->container);

self::assertTrue($this->container->hasDefinition('api_platform.object_mapper.metadata_factory'));
self::assertFalse(class_exists(FrameworkTranslationExtractCommand::class, false));
}

public function testCommonConfiguration(): void
{
$config = self::DEFAULT_CONFIG;
Expand Down
Loading