Skip to content

Commit

Permalink
Handle deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
Zakhar Shokel committed Apr 26, 2024
1 parent ac56e72 commit 9cd3615
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 0 additions & 18 deletions src/DependencyInjection/PayseraApiExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -58,7 +56,6 @@ class_exists(AttributeRouteControllerLoader::class)
}

$this->configurePagination($container, $config['pagination']);
$this->overrideDummyAnnotationRegistry($loader);
}

private function buildPathAttributeResolverDefinition(string $className, string $field): Definition
Expand Down Expand Up @@ -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');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
5 changes: 3 additions & 2 deletions tests/Functional/FunctionalAnnotationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand Down
12 changes: 0 additions & 12 deletions tests/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
}
}
}

0 comments on commit 9cd3615

Please sign in to comment.