Skip to content

Commit 69db87f

Browse files
committed
Compability with doctrine/orm 3
1 parent 9a8a51f commit 69db87f

7 files changed

+35
-18
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"description": "OAuth Server Bundle",
66
"require": {
77
"php": ">=8.1",
8-
"doctrine/orm": "^2.0",
8+
"doctrine/orm": "^2.0 || ^3.0",
99
"symfony/config": "^5.4|^6.0|^7.0",
1010
"symfony/dependency-injection": "^5.4|^6.0|^7.0",
1111
"symfony/event-dispatcher": "^5.4|^6.0|^7.0",

tests/DependencyInjection/OAuthServerExtensionTest.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ public function testLoad(): void
5858
$this->assertInstanceOf(ChainExtractor::class, $container->get(ChainExtractor::class));
5959
$this->assertInstanceOf(MtRandTokenGenerator::class, $container->get(MtRandTokenGenerator::class));
6060

61-
$this->assertInstanceOf(AccessTokenStorage::class, $container->get(AccessTokenStorage::class));
62-
$this->assertInstanceOf(RefreshTokenStorage::class, $container->get(RefreshTokenStorage::class));
63-
$this->assertInstanceOf(AuthCodeStorage::class, $container->get(AuthCodeStorage::class));
64-
$this->assertInstanceOf(ClientStorage::class, $container->get(ClientStorage::class));
61+
$this->assertInstanceOf(AccessTokenStorageInterface::class, $container->get(AccessTokenStorage::class));
62+
$this->assertInstanceOf(RefreshTokenStorageInterface::class, $container->get(RefreshTokenStorage::class));
63+
$this->assertInstanceOf(AuthCodeStorageInterface::class, $container->get(AuthCodeStorage::class));
64+
$this->assertInstanceOf(ClientStorageInterface::class, $container->get(ClientStorage::class));
6565

66-
$this->assertInstanceOf(AccessTokenStorage::class, $container->get(AccessTokenStorageInterface::class));
67-
$this->assertInstanceOf(RefreshTokenStorage::class, $container->get(RefreshTokenStorageInterface::class));
68-
$this->assertInstanceOf(AuthCodeStorage::class, $container->get(AuthCodeStorageInterface::class));
69-
$this->assertInstanceOf(ClientStorage::class, $container->get(ClientStorageInterface::class));
66+
$this->assertInstanceOf(AccessTokenStorageInterface::class, $container->get(AccessTokenStorageInterface::class));
67+
$this->assertInstanceOf(RefreshTokenStorageInterface::class, $container->get(RefreshTokenStorageInterface::class));
68+
$this->assertInstanceOf(AuthCodeStorageInterface::class, $container->get(AuthCodeStorageInterface::class));
69+
$this->assertInstanceOf(ClientStorageInterface::class, $container->get(ClientStorageInterface::class));
7070

7171
$this->assertInstanceOf(AuthCodeGrantExtension::class, $container->get(AuthCodeGrantExtension::class));
7272
$this->assertInstanceOf(ClientCredentialsGrantExtension::class, $container->get(ClientCredentialsGrantExtension::class));

tests/Stub/ContainerTrait.php

+18-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace OAuth\Tests\Stub;
66

77
use Doctrine\ORM\EntityManagerInterface;
8+
use Doctrine\ORM\Mapping\ClassMetadata;
89
use Doctrine\ORM\Tools\Console\EntityManagerProvider;
910
use OAuth\DependencyInjection\OAuthServerExtension;
1011
use OAuth\Tests\Stub\Entity\AccessToken;
@@ -62,12 +63,24 @@ public function mockContainer(): ContainerBuilder
6263

6364
$entityManagerMock
6465
->method('getRepository')
65-
->willReturnCallback(function ($className) {
66+
->willReturnCallback(function ($className) use ($entityManagerMock) {
6667
return match ($className) {
67-
AccessToken::class => new AccessTokenRepositoryStub(),
68-
RefreshToken::class => new RefreshTokenRepositoryStub(),
69-
AuthCode::class => new AuthCodeRepositoryStub(),
70-
Client::class => new ClientRepositoryStub(),
68+
AccessToken::class => new AccessTokenRepositoryStub(
69+
$entityManagerMock,
70+
new ClassMetadata(AccessToken::class)
71+
),
72+
RefreshToken::class => new RefreshTokenRepositoryStub(
73+
$entityManagerMock,
74+
new ClassMetadata(RefreshToken::class)
75+
),
76+
AuthCode::class => new AuthCodeRepositoryStub(
77+
$entityManagerMock,
78+
new ClassMetadata(AuthCode::class)
79+
),
80+
Client::class => new ClientRepositoryStub(
81+
$entityManagerMock,
82+
new ClassMetadata(Client::class)
83+
),
7184
default => throw new \InvalidArgumentException('Unknown repository class'),
7285
};
7386
})

tests/Stub/Repository/AccessTokenRepositoryStub.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
namespace OAuth\Tests\Stub\Repository;
66

7+
use Doctrine\ORM\EntityRepository;
78
use OAuth\Doctrine\Repository\AccessTokenRepositoryInterface;
89
use OAuth\Model\AccessTokenInterface;
910
use OAuth\Model\ClientInterface;
1011
use OAuth\Tests\Stub\Entity\AccessToken;
1112

12-
class AccessTokenRepositoryStub implements AccessTokenRepositoryInterface
13+
class AccessTokenRepositoryStub extends EntityRepository implements AccessTokenRepositoryInterface
1314
{
1415
/** @var array<string, AccessTokenInterface> */
1516
private array $tokens = [];

tests/Stub/Repository/AuthCodeRepositoryStub.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
namespace OAuth\Tests\Stub\Repository;
66

7+
use Doctrine\ORM\EntityRepository;
78
use OAuth\Doctrine\Repository\AuthCodeRepositoryInterface;
89
use OAuth\Model\AuthCodeInterface;
910
use OAuth\Model\ClientInterface;
1011
use OAuth\Tests\Stub\Entity\AuthCode;
1112

12-
class AuthCodeRepositoryStub implements AuthCodeRepositoryInterface
13+
class AuthCodeRepositoryStub extends EntityRepository implements AuthCodeRepositoryInterface
1314
{
1415
/** @var array<string, AuthCodeInterface> */
1516
private array $codes = [];

tests/Stub/Repository/ClientRepositoryStub.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
namespace OAuth\Tests\Stub\Repository;
66

7+
use Doctrine\ORM\EntityRepository;
78
use OAuth\Doctrine\Repository\ClientRepositoryInterface;
89
use OAuth\Model\ClientInterface;
910
use OAuth\Tests\Stub\Entity\Client;
1011

11-
class ClientRepositoryStub implements ClientRepositoryInterface
12+
class ClientRepositoryStub extends EntityRepository implements ClientRepositoryInterface
1213
{
1314
/** @var array<string, ClientInterface> */
1415
private array $tokens = [];

tests/Stub/Repository/RefreshTokenRepositoryStub.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44

55
namespace OAuth\Tests\Stub\Repository;
66

7+
use Doctrine\ORM\EntityRepository;
78
use OAuth\Doctrine\Repository\RefreshTokenRepositoryInterface;
89
use OAuth\Model\ClientInterface;
910
use OAuth\Model\RefreshTokenInterface;
1011
use OAuth\Tests\Stub\Entity\RefreshToken;
1112

12-
class RefreshTokenRepositoryStub implements RefreshTokenRepositoryInterface
13+
class RefreshTokenRepositoryStub extends EntityRepository implements RefreshTokenRepositoryInterface
1314
{
1415
/** @var array<string, RefreshTokenInterface> */
1516
private array $tokens = [];

0 commit comments

Comments
 (0)