diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bccf4fe..6e24837 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,9 @@ name: CI on: push: - branches: [ master, add-php-8-attributes-support ] + branches: [ master ] pull_request: - branches: [ master, add-php-8-attributes-support ] + branches: [ master ] permissions: contents: read diff --git a/src/DependencyInjection/PayseraApiExtension.php b/src/DependencyInjection/PayseraApiExtension.php index fbb12c7..19728fc 100644 --- a/src/DependencyInjection/PayseraApiExtension.php +++ b/src/DependencyInjection/PayseraApiExtension.php @@ -4,7 +4,6 @@ namespace Paysera\Bundle\ApiBundle\DependencyInjection; -use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Persistence\ObjectRepository; use Paysera\Bundle\ApiBundle\Service\PathAttributeResolver\DoctrinePathAttributeResolver; use RuntimeException; @@ -15,7 +14,6 @@ use Symfony\Component\DependencyInjection\Loader; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\Extension; -use Symfony\Component\HttpKernel\Kernel; class PayseraApiExtension extends Extension { @@ -58,7 +56,6 @@ class_exists(AttributeRouteControllerLoader::class) } $this->configurePagination($container, $config['pagination']); - $this->overrideDummyAnnotationRegistry($loader); } private function buildPathAttributeResolverDefinition(string $className, string $field): Definition @@ -92,19 +89,4 @@ private function configurePagination(ContainerBuilder $container, array $paginat $paginationConfig['maximum_limit'] ); } - - private function overrideDummyAnnotationRegistry(Loader\XmlFileLoader $loader): void - { - if (Kernel::VERSION_ID < 40000 || Kernel::VERSION >= 50400) { - return; - } - - // override the dummy registry when doctrine/annotations v2 is used - if ( - !method_exists(AnnotationRegistry::class, 'registerLoader') - || !method_exists(AnnotationRegistry::class, 'registerUniqueLoader') - ) { - $loader->load('annotation_registry.xml'); - } - } } diff --git a/tests/Functional/Fixtures/FixtureTestBundle/DependencyInjection/PayseraFixtureTestExtension.php b/tests/Functional/Fixtures/FixtureTestBundle/DependencyInjection/PayseraFixtureTestExtension.php index 0da7711..a9eb723 100644 --- a/tests/Functional/Fixtures/FixtureTestBundle/DependencyInjection/PayseraFixtureTestExtension.php +++ b/tests/Functional/Fixtures/FixtureTestBundle/DependencyInjection/PayseraFixtureTestExtension.php @@ -3,6 +3,9 @@ namespace Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\DependencyInjection; +use Doctrine\Common\Annotations\AnnotationRegistry; +use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain as LegacyMappingDriverChain; +use Doctrine\Persistence\Mapping\Driver\MappingDriverChain; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; use Symfony\Component\HttpKernel\DependencyInjection\Extension; @@ -27,5 +30,26 @@ public function load(array $configs, ContainerBuilder $container) $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $prefix = Kernel::MAJOR_VERSION <= 4 ? 'legacy_' : ''; $loader->load($prefix . 'services.xml'); + + $this->handleDeprecations($container, $loader); + } + + public function handleDeprecations(ContainerBuilder $container, Loader\XmlFileLoader $loader): void + { + if (Kernel::VERSION_ID < 40000 || Kernel::VERSION >= 50400) { + return; + } + + // override the dummy registry when doctrine/annotations v2 is used + if ( + !method_exists(AnnotationRegistry::class, 'registerLoader') + || !method_exists(AnnotationRegistry::class, 'registerUniqueLoader') + ) { + $loader->load('annotation_registry.xml'); + } + + if (!class_exists(LegacyMappingDriverChain::class)) { + $container->setParameter('doctrine.orm.metadata.driver_chain.class', MappingDriverChain::class); + } } } diff --git a/src/Resources/config/services/annotation_registry.xml b/tests/Functional/Fixtures/FixtureTestBundle/Resources/config/annotation_registry.xml similarity index 100% rename from src/Resources/config/services/annotation_registry.xml rename to tests/Functional/Fixtures/FixtureTestBundle/Resources/config/annotation_registry.xml diff --git a/tests/Functional/Fixtures/FixtureTestBundle/Service/TestHelper.php b/tests/Functional/Fixtures/FixtureTestBundle/Service/TestHelper.php index 125f47d..6510d22 100644 --- a/tests/Functional/Fixtures/FixtureTestBundle/Service/TestHelper.php +++ b/tests/Functional/Fixtures/FixtureTestBundle/Service/TestHelper.php @@ -4,10 +4,12 @@ namespace Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Service; +use Symfony\Bundle\FrameworkBundle\Routing\AttributeRouteControllerLoader; + class TestHelper { public static function phpAttributeSupportExists(): bool { - return PHP_VERSION_ID >= 80100; + return PHP_VERSION_ID >= 80100 && class_exists(AttributeRouteControllerLoader::class); } } diff --git a/tests/Functional/FunctionalAnnotationsTest.php b/tests/Functional/FunctionalAnnotationsTest.php index 946146e..41b6f7f 100644 --- a/tests/Functional/FunctionalAnnotationsTest.php +++ b/tests/Functional/FunctionalAnnotationsTest.php @@ -3,6 +3,7 @@ namespace Paysera\Bundle\ApiBundle\Tests\Functional; +use Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Service\TestHelper; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -48,8 +49,8 @@ private function makeTest( Request $request, Response $extraResponseVersion = null ): void { - if ($pathPrefix === 'attributed') { - $this->checkAttributeConfigurationSupport(); + if ($pathPrefix === 'attributed' && !TestHelper::phpAttributeSupportExists()) { + $this->markTestSkipped('Unsupported environment'); } $request->server->set( diff --git a/tests/Functional/FunctionalTestCase.php b/tests/Functional/FunctionalTestCase.php index d0185de..0a1f80e 100644 --- a/tests/Functional/FunctionalTestCase.php +++ b/tests/Functional/FunctionalTestCase.php @@ -5,7 +5,6 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Tools\SchemaTool; -use Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\FixtureTestBundle\Service\TestHelper; use Paysera\Bundle\ApiBundle\Tests\Functional\Fixtures\TestKernel; use PHPUnit\Framework\TestCase; use Symfony\Bundle\FrameworkBundle\Routing\AttributeRouteControllerLoader; @@ -110,15 +109,4 @@ protected function getEntityManager(): EntityManagerInterface { return $this->kernel->getContainer()->get('doctrine.orm.entity_manager'); } - - protected function checkAttributeConfigurationSupport(): void - { - if (!class_exists(AttributeRouteControllerLoader::class)) { - $this->markTestSkipped('Unsupported Symfony version'); - } - - if (!TestHelper::phpAttributeSupportExists()) { - $this->markTestSkipped('Unsupported PHP version'); - } - } }