From 69db87f4345491a110df0ae8004e3bfb81c59678 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Mon, 21 Oct 2024 21:25:01 +0300 Subject: [PATCH] Compability with doctrine/orm 3 --- composer.json | 2 +- .../OAuthServerExtensionTest.php | 16 ++++++------- tests/Stub/ContainerTrait.php | 23 +++++++++++++++---- .../Repository/AccessTokenRepositoryStub.php | 3 ++- .../Repository/AuthCodeRepositoryStub.php | 3 ++- .../Stub/Repository/ClientRepositoryStub.php | 3 ++- .../Repository/RefreshTokenRepositoryStub.php | 3 ++- 7 files changed, 35 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 7a93c52..e3f3cce 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "description": "OAuth Server Bundle", "require": { "php": ">=8.1", - "doctrine/orm": "^2.0", + "doctrine/orm": "^2.0 || ^3.0", "symfony/config": "^5.4|^6.0|^7.0", "symfony/dependency-injection": "^5.4|^6.0|^7.0", "symfony/event-dispatcher": "^5.4|^6.0|^7.0", diff --git a/tests/DependencyInjection/OAuthServerExtensionTest.php b/tests/DependencyInjection/OAuthServerExtensionTest.php index c9fc9ab..4be0f60 100644 --- a/tests/DependencyInjection/OAuthServerExtensionTest.php +++ b/tests/DependencyInjection/OAuthServerExtensionTest.php @@ -58,15 +58,15 @@ public function testLoad(): void $this->assertInstanceOf(ChainExtractor::class, $container->get(ChainExtractor::class)); $this->assertInstanceOf(MtRandTokenGenerator::class, $container->get(MtRandTokenGenerator::class)); - $this->assertInstanceOf(AccessTokenStorage::class, $container->get(AccessTokenStorage::class)); - $this->assertInstanceOf(RefreshTokenStorage::class, $container->get(RefreshTokenStorage::class)); - $this->assertInstanceOf(AuthCodeStorage::class, $container->get(AuthCodeStorage::class)); - $this->assertInstanceOf(ClientStorage::class, $container->get(ClientStorage::class)); + $this->assertInstanceOf(AccessTokenStorageInterface::class, $container->get(AccessTokenStorage::class)); + $this->assertInstanceOf(RefreshTokenStorageInterface::class, $container->get(RefreshTokenStorage::class)); + $this->assertInstanceOf(AuthCodeStorageInterface::class, $container->get(AuthCodeStorage::class)); + $this->assertInstanceOf(ClientStorageInterface::class, $container->get(ClientStorage::class)); - $this->assertInstanceOf(AccessTokenStorage::class, $container->get(AccessTokenStorageInterface::class)); - $this->assertInstanceOf(RefreshTokenStorage::class, $container->get(RefreshTokenStorageInterface::class)); - $this->assertInstanceOf(AuthCodeStorage::class, $container->get(AuthCodeStorageInterface::class)); - $this->assertInstanceOf(ClientStorage::class, $container->get(ClientStorageInterface::class)); + $this->assertInstanceOf(AccessTokenStorageInterface::class, $container->get(AccessTokenStorageInterface::class)); + $this->assertInstanceOf(RefreshTokenStorageInterface::class, $container->get(RefreshTokenStorageInterface::class)); + $this->assertInstanceOf(AuthCodeStorageInterface::class, $container->get(AuthCodeStorageInterface::class)); + $this->assertInstanceOf(ClientStorageInterface::class, $container->get(ClientStorageInterface::class)); $this->assertInstanceOf(AuthCodeGrantExtension::class, $container->get(AuthCodeGrantExtension::class)); $this->assertInstanceOf(ClientCredentialsGrantExtension::class, $container->get(ClientCredentialsGrantExtension::class)); diff --git a/tests/Stub/ContainerTrait.php b/tests/Stub/ContainerTrait.php index 365280b..f7a060b 100644 --- a/tests/Stub/ContainerTrait.php +++ b/tests/Stub/ContainerTrait.php @@ -5,6 +5,7 @@ namespace OAuth\Tests\Stub; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Tools\Console\EntityManagerProvider; use OAuth\DependencyInjection\OAuthServerExtension; use OAuth\Tests\Stub\Entity\AccessToken; @@ -62,12 +63,24 @@ public function mockContainer(): ContainerBuilder $entityManagerMock ->method('getRepository') - ->willReturnCallback(function ($className) { + ->willReturnCallback(function ($className) use ($entityManagerMock) { return match ($className) { - AccessToken::class => new AccessTokenRepositoryStub(), - RefreshToken::class => new RefreshTokenRepositoryStub(), - AuthCode::class => new AuthCodeRepositoryStub(), - Client::class => new ClientRepositoryStub(), + AccessToken::class => new AccessTokenRepositoryStub( + $entityManagerMock, + new ClassMetadata(AccessToken::class) + ), + RefreshToken::class => new RefreshTokenRepositoryStub( + $entityManagerMock, + new ClassMetadata(RefreshToken::class) + ), + AuthCode::class => new AuthCodeRepositoryStub( + $entityManagerMock, + new ClassMetadata(AuthCode::class) + ), + Client::class => new ClientRepositoryStub( + $entityManagerMock, + new ClassMetadata(Client::class) + ), default => throw new \InvalidArgumentException('Unknown repository class'), }; }) diff --git a/tests/Stub/Repository/AccessTokenRepositoryStub.php b/tests/Stub/Repository/AccessTokenRepositoryStub.php index 58bf36a..5151747 100644 --- a/tests/Stub/Repository/AccessTokenRepositoryStub.php +++ b/tests/Stub/Repository/AccessTokenRepositoryStub.php @@ -4,12 +4,13 @@ namespace OAuth\Tests\Stub\Repository; +use Doctrine\ORM\EntityRepository; use OAuth\Doctrine\Repository\AccessTokenRepositoryInterface; use OAuth\Model\AccessTokenInterface; use OAuth\Model\ClientInterface; use OAuth\Tests\Stub\Entity\AccessToken; -class AccessTokenRepositoryStub implements AccessTokenRepositoryInterface +class AccessTokenRepositoryStub extends EntityRepository implements AccessTokenRepositoryInterface { /** @var array */ private array $tokens = []; diff --git a/tests/Stub/Repository/AuthCodeRepositoryStub.php b/tests/Stub/Repository/AuthCodeRepositoryStub.php index 1f95e0e..ce7ec32 100644 --- a/tests/Stub/Repository/AuthCodeRepositoryStub.php +++ b/tests/Stub/Repository/AuthCodeRepositoryStub.php @@ -4,12 +4,13 @@ namespace OAuth\Tests\Stub\Repository; +use Doctrine\ORM\EntityRepository; use OAuth\Doctrine\Repository\AuthCodeRepositoryInterface; use OAuth\Model\AuthCodeInterface; use OAuth\Model\ClientInterface; use OAuth\Tests\Stub\Entity\AuthCode; -class AuthCodeRepositoryStub implements AuthCodeRepositoryInterface +class AuthCodeRepositoryStub extends EntityRepository implements AuthCodeRepositoryInterface { /** @var array */ private array $codes = []; diff --git a/tests/Stub/Repository/ClientRepositoryStub.php b/tests/Stub/Repository/ClientRepositoryStub.php index 781bb0e..dbdc082 100644 --- a/tests/Stub/Repository/ClientRepositoryStub.php +++ b/tests/Stub/Repository/ClientRepositoryStub.php @@ -4,11 +4,12 @@ namespace OAuth\Tests\Stub\Repository; +use Doctrine\ORM\EntityRepository; use OAuth\Doctrine\Repository\ClientRepositoryInterface; use OAuth\Model\ClientInterface; use OAuth\Tests\Stub\Entity\Client; -class ClientRepositoryStub implements ClientRepositoryInterface +class ClientRepositoryStub extends EntityRepository implements ClientRepositoryInterface { /** @var array */ private array $tokens = []; diff --git a/tests/Stub/Repository/RefreshTokenRepositoryStub.php b/tests/Stub/Repository/RefreshTokenRepositoryStub.php index 1a92f8c..2da2139 100644 --- a/tests/Stub/Repository/RefreshTokenRepositoryStub.php +++ b/tests/Stub/Repository/RefreshTokenRepositoryStub.php @@ -4,12 +4,13 @@ namespace OAuth\Tests\Stub\Repository; +use Doctrine\ORM\EntityRepository; use OAuth\Doctrine\Repository\RefreshTokenRepositoryInterface; use OAuth\Model\ClientInterface; use OAuth\Model\RefreshTokenInterface; use OAuth\Tests\Stub\Entity\RefreshToken; -class RefreshTokenRepositoryStub implements RefreshTokenRepositoryInterface +class RefreshTokenRepositoryStub extends EntityRepository implements RefreshTokenRepositoryInterface { /** @var array */ private array $tokens = [];