From 4f416e1b82b38af113692bc9fdb3258f2e51f42b Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Mon, 8 Feb 2021 09:47:31 -0300 Subject: [PATCH] Add support for "doctrine/common:^3" --- composer.json | 3 ++- src/DependencyInjection/SonataUserExtension.php | 17 +++++++++++++++++ src/Entity/UserManagerProxy.php | 4 +--- tests/Entity/UserManagerProxyTest.php | 4 ++-- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 576a24e81..782bb1ec8 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ ], "require": { "php": "^7.3", - "doctrine/common": "^2.0", + "doctrine/common": "^2.0 || ^3.1", + "doctrine/persistence": "^1.3 || ^2.1", "friendsofsymfony/user-bundle": "^2.0", "sonata-project/admin-bundle": "^3.76", "sonata-project/datagrid-bundle": "^3.0.1", diff --git a/src/DependencyInjection/SonataUserExtension.php b/src/DependencyInjection/SonataUserExtension.php index f4ccd0307..cba536d34 100644 --- a/src/DependencyInjection/SonataUserExtension.php +++ b/src/DependencyInjection/SonataUserExtension.php @@ -126,6 +126,8 @@ class_exists('Sonata\GoogleAuthenticator\GoogleAuthenticator')) { $container->setParameter('sonata.user.impersonating', $config['impersonating']); $this->configureGoogleAuthenticator($config, $container); + + $this->createDoctrineCommonBackwardCompatibilityAliases(); } /** @@ -369,4 +371,19 @@ private function registerSonataDoctrineMapping(array $config): void ]]) ); } + + /** + * We MUST remove this method when support for "friendsofsymfony/user-bundle" is dropped + * or adapted to work with "doctrine/common:^3". + */ + private function createDoctrineCommonBackwardCompatibilityAliases(): void + { + if (!interface_exists(\Doctrine\Common\Persistence\ObjectManager::class)) { + class_alias(\Doctrine\Persistence\ObjectManager::class, \Doctrine\Common\Persistence\ObjectManager::class); + } + + if (!class_exists(\Doctrine\Common\Persistence\Event\LifecycleEventArgs::class)) { + class_alias(\Doctrine\Persistence\Event\LifecycleEventArgs::class, \Doctrine\Common\Persistence\Event\LifecycleEventArgs::class); + } + } } diff --git a/src/Entity/UserManagerProxy.php b/src/Entity/UserManagerProxy.php index 8bec20a73..274187451 100644 --- a/src/Entity/UserManagerProxy.php +++ b/src/Entity/UserManagerProxy.php @@ -13,7 +13,7 @@ namespace Sonata\UserBundle\Entity; -use Doctrine\Common\Persistence\ManagerRegistry; +use Doctrine\Persistence\ManagerRegistry; use Sonata\Doctrine\Entity\BaseEntityManager; /** @@ -30,8 +30,6 @@ class UserManagerProxy extends BaseEntityManager protected $userManager; /** - * UserManagerProxy constructor. - * * @param string $class */ public function __construct($class, ManagerRegistry $registry, UserManager $userManager) diff --git a/tests/Entity/UserManagerProxyTest.php b/tests/Entity/UserManagerProxyTest.php index cbd28ec48..1b5310ede 100644 --- a/tests/Entity/UserManagerProxyTest.php +++ b/tests/Entity/UserManagerProxyTest.php @@ -13,7 +13,7 @@ namespace Sonata\UserBundle\Tests\Entity; -use Doctrine\Common\Persistence\ManagerRegistry; +use Doctrine\Persistence\ManagerRegistry; use PHPUnit\Framework\TestCase; use Sonata\UserBundle\Entity\UserManager; use Sonata\UserBundle\Entity\UserManagerProxy; @@ -22,7 +22,7 @@ class UserManagerProxyTest extends TestCase { public function testProxy(): void { - $doctrine = $this->getMockBuilder(ManagerRegistry::class)->disableOriginalConstructor()->getMock(); + $doctrine = $this->createStub(ManagerRegistry::class); $userManager = $this->getMockBuilder(UserManager::class)->disableOriginalConstructor()->getMock();