From be7b9c2723ef3d60ddfb6cf842dfa13ee183e8ff Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Fri, 6 Oct 2023 15:34:48 -0400 Subject: [PATCH] Add support for Symfony 7, require Symfony 5.4+ and PHP 7.4+ --- .github/workflows/ci.yaml | 4 +-- .phpcs.xml.dist | 2 +- Cache/CacheWarmer.php | 2 +- DependencyInjection/Configuration.php | 5 +-- .../JMSSerializerExtension.php | 12 +++---- .../BasicSerializerFunctionsProvider.php | 2 +- .../DependencyInjection/ConfigurationTest.php | 5 ++- .../JMSSerializerExtensionTest.php | 12 +++---- composer.json | 31 ++++++++++--------- 9 files changed, 35 insertions(+), 40 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8eb95ac5..3cf22229 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,8 +17,6 @@ jobs: strategy: matrix: php-version: - - "7.2" - - "7.3" - "7.4" - "8.0" - "8.1" @@ -26,7 +24,7 @@ jobs: dependencies: - "highest" include: - - php-version: "7.2" + - php-version: "7.4" dependencies: "lowest" steps: diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 73ddd005..a77e830e 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -10,7 +10,7 @@ - + Cache/ ContextFactory/ diff --git a/Cache/CacheWarmer.php b/Cache/CacheWarmer.php index 372e7a90..6295a65d 100644 --- a/Cache/CacheWarmer.php +++ b/Cache/CacheWarmer.php @@ -38,7 +38,7 @@ public function __construct(array $includePaths, MetadataFactoryInterface $metad * * @return string[] A list of classes or files to preload on PHP 7.4+ */ - public function warmUp($cacheDir) + public function warmUp(string $cacheDir, ?string $buildDir = null): array { $finder = Finder::create() ->ignoreVCS(true) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 173129a9..b3c896c6 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -25,10 +25,7 @@ public function __construct($debug = false) $this->debug = $debug; } - /** - * @return TreeBuilder - */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $tb = new TreeBuilder('jms_serializer'); diff --git a/DependencyInjection/JMSSerializerExtension.php b/DependencyInjection/JMSSerializerExtension.php index f301d6e1..75b72388 100644 --- a/DependencyInjection/JMSSerializerExtension.php +++ b/DependencyInjection/JMSSerializerExtension.php @@ -253,14 +253,10 @@ private function loadInternal(array $config, ScopedContainer $container, array $ $container->removeDefinition('jms_serializer.metadata.doc_block_driver'); } - // enable the typed props reader on php 7.4+ - if (PHP_VERSION_ID >= 70400) { - $container->getDefinition('jms_serializer.metadata.typed_properties_driver') - ->setDecoratedService('jms_serializer.metadata_driver') - ->setPublic(false); - } else { - $container->removeDefinition('jms_serializer.metadata.typed_properties_driver'); - } + // enable the typed props reader + $container->getDefinition('jms_serializer.metadata.typed_properties_driver') + ->setDecoratedService('jms_serializer.metadata_driver') + ->setPublic(false); if ($config['enum_support']) { $container->getDefinition('jms_serializer.metadata.enum_driver') diff --git a/ExpressionLanguage/BasicSerializerFunctionsProvider.php b/ExpressionLanguage/BasicSerializerFunctionsProvider.php index eff59a5f..9b58ebf9 100644 --- a/ExpressionLanguage/BasicSerializerFunctionsProvider.php +++ b/ExpressionLanguage/BasicSerializerFunctionsProvider.php @@ -12,7 +12,7 @@ class BasicSerializerFunctionsProvider implements ExpressionFunctionProviderInte /** * @return ExpressionFunction[] */ - public function getFunctions() + public function getFunctions(): array { return [ new ExpressionFunction('service', static function ($arg) { diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 55e9fcf9..9b783713 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -19,7 +19,10 @@ private function getContainer(array $configs = []) $bundles = ['JMSSerializerBundle' => 'JMS\SerializerBundle\JMSSerializerBundle']; $container = new ContainerBuilder(); - $container->set('annotation_reader', new AnnotationReader()); + if (class_exists(AnnotationReader::class)) { + $container->set('annotation_reader', new AnnotationReader()); + } + $container->setParameter('kernel.debug', true); $container->setParameter('kernel.cache_dir', sys_get_temp_dir() . '/serializer'); $container->setParameter('kernel.bundles', $bundles); diff --git a/Tests/DependencyInjection/JMSSerializerExtensionTest.php b/Tests/DependencyInjection/JMSSerializerExtensionTest.php index 9631c1b9..44f510cc 100644 --- a/Tests/DependencyInjection/JMSSerializerExtensionTest.php +++ b/Tests/DependencyInjection/JMSSerializerExtensionTest.php @@ -32,7 +32,7 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -use Twig\Loader\ContainerRuntimeLoader; +use Twig\RuntimeLoader\ContainerRuntimeLoader; class JMSSerializerExtensionTest extends TestCase { @@ -777,10 +777,6 @@ public function testAutoconfigureHandlers() public function testTypedDriverIsEnabled() { - if (PHP_VERSION_ID < 70400) { - $this->markTestSkipped(sprintf('%s requires PHP 7.4', __METHOD__)); - } - if (!class_exists(TypedPropertiesDriver::class)) { $this->markTestSkipped(sprintf('%s requires %s', __METHOD__, TypedPropertiesDriver::class)); } @@ -872,7 +868,11 @@ private function getContainerForConfigLoad(array $configs, ?callable $configurat $container->setParameter('kernel.bundles', []); $container->setParameter('kernel.bundles_metadata', []); $container->setParameter('foo', 'bar'); - $container->set('annotation_reader', new AnnotationReader()); + + if (class_exists(AnnotationReader::class)) { + $container->set('annotation_reader', new AnnotationReader()); + } + $container->setDefinition('doctrine', new Definition(Registry::class)); // $container->setDefinition('doctrine.orm.entity_manager', new Definition(EntityManager::class)); diff --git a/composer.json b/composer.json index 39a848ba..1edab190 100644 --- a/composer.json +++ b/composer.json @@ -21,29 +21,30 @@ } ], "require": { - "php": "^7.2 || ^8.0", + "php": "^7.4 || ^8.0", "jms/serializer": "^3.28", "jms/metadata": "^2.6", - "symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0" + "symfony/config": "^5.4 || ^6.0 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0", + "symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0" }, "require-dev": { "doctrine/coding-standard": "^8.1", - "doctrine/orm": "^2.4", + "doctrine/orm": "^2.14", "phpunit/phpunit": "^8.0 || ^9.0", - "symfony/expression-language": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/finder": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/form": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/stopwatch": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/templating": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/twig-bundle": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/uid": "^5.1 || ^6.0", - "symfony/validator": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0" + "symfony/expression-language": "^5.4 || ^6.0 || ^7.0", + "symfony/finder": "^5.4 || ^6.0 || ^7.0", + "symfony/form": "^5.4 || ^6.0 || ^7.0", + "symfony/stopwatch": "^5.4 || ^6.0 || ^7.0", + "symfony/templating": "^5.4 || ^6.0", + "symfony/twig-bundle": "^5.4 || ^6.0 || ^7.0", + "symfony/uid": "^5.4 || ^6.0 || ^7.0", + "symfony/validator": "^5.4 || ^6.0 || ^7.0", + "symfony/yaml": "^5.4 || ^6.0 || ^7.0" }, "suggest": { - "symfony/expression-language": "Required for opcache preloading ^3.4 || ^4.0 || ^5.0 || ^6.0", - "symfony/finder": "Required for cache warmup, supported versions ^3.4 || ^4.0 || ^5.0 || ^6.0" + "symfony/expression-language": "Required for opcache preloading ^5.4 || ^6.0 || ^7.0", + "symfony/finder": "Required for cache warmup, supported versions ^5.4 || ^6.0 || ^7.0" }, "config": { "allow-plugins": {