Skip to content

Commit

Permalink
Compability with doctrine/orm 3
Browse files Browse the repository at this point in the history
  • Loading branch information
muxx committed Oct 21, 2024
1 parent 9a8a51f commit 69db87f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions tests/DependencyInjection/OAuthServerExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
23 changes: 18 additions & 5 deletions tests/Stub/ContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
};
})
Expand Down
3 changes: 2 additions & 1 deletion tests/Stub/Repository/AccessTokenRepositoryStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, AccessTokenInterface> */
private array $tokens = [];
Expand Down
3 changes: 2 additions & 1 deletion tests/Stub/Repository/AuthCodeRepositoryStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, AuthCodeInterface> */
private array $codes = [];
Expand Down
3 changes: 2 additions & 1 deletion tests/Stub/Repository/ClientRepositoryStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ClientInterface> */
private array $tokens = [];
Expand Down
3 changes: 2 additions & 1 deletion tests/Stub/Repository/RefreshTokenRepositoryStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, RefreshTokenInterface> */
private array $tokens = [];
Expand Down

0 comments on commit 69db87f

Please sign in to comment.