diff --git a/Document/AuthCodeManager.php b/Document/AuthCodeManager.php index bdcc2ad1..01331ed6 100644 --- a/Document/AuthCodeManager.php +++ b/Document/AuthCodeManager.php @@ -14,7 +14,6 @@ namespace FOS\OAuthServerBundle\Document; use Doctrine\ODM\MongoDB\DocumentManager; -use Doctrine\ODM\MongoDB\DocumentRepository; use FOS\OAuthServerBundle\Model\AuthCodeInterface; use FOS\OAuthServerBundle\Model\AuthCodeManager as BaseAuthCodeManager; @@ -25,11 +24,6 @@ class AuthCodeManager extends BaseAuthCodeManager */ protected $dm; - /** - * @var DocumentRepository - */ - protected $repository; - /** * @var string */ @@ -37,12 +31,7 @@ class AuthCodeManager extends BaseAuthCodeManager public function __construct(DocumentManager $dm, $class) { - // NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected - /** @var DocumentRepository $repository */ - $repository = $dm->getRepository($class); - $this->dm = $dm; - $this->repository = $repository; $this->class = $class; } @@ -59,7 +48,7 @@ public function getClass() */ public function findAuthCodeBy(array $criteria) { - return $this->repository->findOneBy($criteria); + return $this->dm->getRepository($this->class)->findOneBy($criteria); } /** @@ -85,8 +74,10 @@ public function deleteAuthCode(AuthCodeInterface $authCode) */ public function deleteExpired() { - $result = $this - ->repository + /** @var \Doctrine\ODM\MongoDB\DocumentRepository $repository */ + $repository = $this->dm->getRepository($this->class); + + $result = $repository ->createQueryBuilder() ->remove() ->field('expiresAt')->lt(time()) diff --git a/Document/ClientManager.php b/Document/ClientManager.php index 73a95d63..1e04bc6a 100644 --- a/Document/ClientManager.php +++ b/Document/ClientManager.php @@ -14,7 +14,6 @@ namespace FOS\OAuthServerBundle\Document; use Doctrine\ODM\MongoDB\DocumentManager; -use Doctrine\ODM\MongoDB\DocumentRepository; use FOS\OAuthServerBundle\Model\ClientInterface; use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager; @@ -25,11 +24,6 @@ class ClientManager extends BaseClientManager */ protected $dm; - /** - * @var DocumentRepository - */ - protected $repository; - /** * @var string */ @@ -37,12 +31,7 @@ class ClientManager extends BaseClientManager public function __construct(DocumentManager $dm, $class) { - // NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected - /** @var DocumentRepository $repository */ - $repository = $dm->getRepository($class); - $this->dm = $dm; - $this->repository = $repository; $this->class = $class; } @@ -59,7 +48,7 @@ public function getClass() */ public function findClientBy(array $criteria) { - return $this->repository->findOneBy($criteria); + return $this->dm->getRepository($this->class)->findOneBy($criteria); } /** diff --git a/Document/TokenManager.php b/Document/TokenManager.php index 9050924d..ebc75615 100644 --- a/Document/TokenManager.php +++ b/Document/TokenManager.php @@ -25,11 +25,6 @@ class TokenManager extends BaseTokenManager */ protected $dm; - /** - * @var DocumentRepository - */ - protected $repository; - /** * @var string */ @@ -37,12 +32,7 @@ class TokenManager extends BaseTokenManager public function __construct(DocumentManager $dm, $class) { - // NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected - /** @var DocumentRepository $repository */ - $repository = $dm->getRepository($class); - $this->dm = $dm; - $this->repository = $repository; $this->class = $class; } @@ -59,7 +49,7 @@ public function getClass() */ public function findTokenBy(array $criteria) { - return $this->repository->findOneBy($criteria); + return $this->dm->getRepository($this->class)->findOneBy($criteria); } /** @@ -85,8 +75,10 @@ public function deleteToken(TokenInterface $token) */ public function deleteExpired() { - $result = $this - ->repository + // NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected + /** @var DocumentRepository $repository */ + $repository = $this->dm->getRepository($this->class); + $result = $repository ->createQueryBuilder() ->remove() ->field('expiresAt')->lt(time()) diff --git a/Entity/ClientManager.php b/Entity/ClientManager.php index 346c9732..b0699530 100644 --- a/Entity/ClientManager.php +++ b/Entity/ClientManager.php @@ -14,7 +14,6 @@ namespace FOS\OAuthServerBundle\Entity; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\EntityRepository; use FOS\OAuthServerBundle\Model\ClientInterface; use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager; @@ -25,11 +24,6 @@ class ClientManager extends BaseClientManager */ protected $em; - /** - * @var EntityRepository - */ - protected $repository; - /** * @var string */ @@ -37,12 +31,7 @@ class ClientManager extends BaseClientManager public function __construct(EntityManagerInterface $em, $class) { - // NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected - /** @var EntityRepository $repository */ - $repository = $em->getRepository($class); - $this->em = $em; - $this->repository = $repository; $this->class = $class; } @@ -59,7 +48,7 @@ public function getClass() */ public function findClientBy(array $criteria) { - return $this->repository->findOneBy($criteria); + return $this->em->getRepository($this->class)->findOneBy($criteria); } /** diff --git a/Entity/TokenManager.php b/Entity/TokenManager.php index 4a87c17f..73458f13 100644 --- a/Entity/TokenManager.php +++ b/Entity/TokenManager.php @@ -25,11 +25,6 @@ class TokenManager extends BaseTokenManager */ protected $em; - /** - * @var EntityRepository - */ - protected $repository; - /** * @var string */ @@ -37,12 +32,7 @@ class TokenManager extends BaseTokenManager public function __construct(EntityManagerInterface $em, $class) { - // NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected - /** @var EntityRepository $repository */ - $repository = $em->getRepository($class); - $this->em = $em; - $this->repository = $repository; $this->class = $class; } @@ -59,7 +49,7 @@ public function getClass() */ public function findTokenBy(array $criteria) { - return $this->repository->findOneBy($criteria); + return $this->em->getRepository($this->class)->findOneBy($criteria); } /** @@ -85,7 +75,10 @@ public function deleteToken(TokenInterface $token) */ public function deleteExpired() { - $qb = $this->repository->createQueryBuilder('t'); + // NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected + /** @var EntityRepository $repository */ + $repository = $this->em->getRepository($this->class); + $qb = $repository->createQueryBuilder('t'); $qb ->delete() ->where('t.expiresAt < ?1') diff --git a/Tests/Document/AuthCodeManagerTest.php b/Tests/Document/AuthCodeManagerTest.php index f3a86281..020798ac 100644 --- a/Tests/Document/AuthCodeManagerTest.php +++ b/Tests/Document/AuthCodeManagerTest.php @@ -65,13 +65,6 @@ public function setUp() ; $this->className = 'TestClassName'.\random_bytes(5); - $this->documentManager - ->expects($this->once()) - ->method('getRepository') - ->with($this->className) - ->willReturn($this->repository) - ; - $this->instance = new AuthCodeManager($this->documentManager, $this->className); parent::setUp(); @@ -95,6 +88,13 @@ public function testFindAuthCodeBy() \random_bytes(10), ]; + $this->documentManager + ->expects($this->once()) + ->method('getRepository') + ->with($this->className) + ->willReturn($this->repository) + ; + $this->repository ->expects($this->once()) ->method('findOneBy') @@ -155,6 +155,13 @@ public function testDeleteAuthCode() public function testDeleteExpired() { + $this->documentManager + ->expects($this->once()) + ->method('getRepository') + ->with($this->className) + ->willReturn($this->repository) + ; + $queryBuilder = $this->getMockBuilder(Builder::class) ->disableOriginalConstructor() ->getMock() diff --git a/Tests/Document/ClientManagerTest.php b/Tests/Document/ClientManagerTest.php index 4af23fc8..4fecd3ba 100644 --- a/Tests/Document/ClientManagerTest.php +++ b/Tests/Document/ClientManagerTest.php @@ -61,13 +61,6 @@ public function setUp() ; $this->className = 'RandomClassName'.\random_bytes(5); - $this->documentManager - ->expects($this->once()) - ->method('getRepository') - ->with($this->className) - ->willReturn($this->repository) - ; - $this->instance = new ClientManager($this->documentManager, $this->className); parent::setUp(); @@ -76,7 +69,6 @@ public function setUp() public function testConstructWillSetParameters() { $this->assertAttributeSame($this->documentManager, 'dm', $this->instance); - $this->assertAttributeSame($this->repository, 'repository', $this->instance); $this->assertAttributeSame($this->className, 'class', $this->instance); } @@ -92,6 +84,13 @@ public function testFindClientBy() \random_bytes(5), ]; + $this->documentManager + ->expects($this->once()) + ->method('getRepository') + ->with($this->className) + ->willReturn($this->repository) + ; + $this->repository ->expects($this->once()) ->method('findOneBy') diff --git a/Tests/Document/TokenManagerTest.php b/Tests/Document/TokenManagerTest.php index ff166d34..533854db 100644 --- a/Tests/Document/TokenManagerTest.php +++ b/Tests/Document/TokenManagerTest.php @@ -65,13 +65,6 @@ public function setUp() ->getMock() ; - $this->documentManager - ->expects($this->once()) - ->method('getRepository') - ->with($this->className) - ->willReturn($this->repository) - ; - $this->instance = new TokenManager($this->documentManager, $this->className); } @@ -80,6 +73,13 @@ public function testFindTokenByToken() $randomToken = \random_bytes(5); $randomResult = \random_bytes(5); + $this->documentManager + ->expects($this->once()) + ->method('getRepository') + ->with($this->className) + ->willReturn($this->repository) + ; + $this->repository ->expects($this->once()) ->method('findOneBy') @@ -145,6 +145,13 @@ public function testDeleteToken() public function testDeleteExpired() { + $this->documentManager + ->expects($this->once()) + ->method('getRepository') + ->with($this->className) + ->willReturn($this->repository) + ; + $queryBuilder = $this->getMockBuilder(Builder::class) ->disableOriginalConstructor() ->getMock() diff --git a/Tests/Entity/ClientManagerTest.php b/Tests/Entity/ClientManagerTest.php index d575d320..cfcd9e68 100644 --- a/Tests/Entity/ClientManagerTest.php +++ b/Tests/Entity/ClientManagerTest.php @@ -57,13 +57,6 @@ public function setUp() ; $this->className = 'RandomClassName'.\random_bytes(5); - $this->entityManager - ->expects($this->once()) - ->method('getRepository') - ->with($this->className) - ->willReturn($this->repository) - ; - $this->instance = new ClientManager($this->entityManager, $this->className); parent::setUp(); @@ -72,7 +65,6 @@ public function setUp() public function testConstructWillSetParameters() { $this->assertAttributeSame($this->entityManager, 'em', $this->instance); - $this->assertAttributeSame($this->repository, 'repository', $this->instance); $this->assertAttributeSame($this->className, 'class', $this->instance); } @@ -88,6 +80,13 @@ public function testFindClientBy() ]; $randomResult = \random_bytes(5); + $this->entityManager + ->expects($this->once()) + ->method('getRepository') + ->with($this->className) + ->willReturn($this->repository) + ; + $this->repository ->expects($this->once()) ->method('findOneBy') diff --git a/Tests/Entity/TokenManagerTest.php b/Tests/Entity/TokenManagerTest.php index acdeca16..7bce37e0 100644 --- a/Tests/Entity/TokenManagerTest.php +++ b/Tests/Entity/TokenManagerTest.php @@ -63,20 +63,12 @@ public function setUp() ->getMock() ; - $this->entityManager - ->expects($this->once()) - ->method('getRepository') - ->with($this->className) - ->willReturn($this->repository) - ; - $this->instance = new TokenManager($this->entityManager, $this->className); } public function testConstructWillSetParameters() { $this->assertAttributeSame($this->entityManager, 'em', $this->instance); - $this->assertAttributeSame($this->repository, 'repository', $this->instance); $this->assertAttributeSame($this->className, 'class', $this->instance); } @@ -112,6 +104,13 @@ public function testFindTokenBy() \random_bytes(5), ]; + $this->entityManager + ->expects($this->once()) + ->method('getRepository') + ->with($this->className) + ->willReturn($this->repository) + ; + $this->repository ->expects($this->once()) ->method('findOneBy') @@ -174,6 +173,13 @@ public function testDeleteExpired() { $randomResult = \random_bytes(10); + $this->entityManager + ->expects($this->once()) + ->method('getRepository') + ->with($this->className) + ->willReturn($this->repository) + ; + $queryBuilder = $this->getMockBuilder(QueryBuilder::class) ->disableOriginalConstructor() ->getMock()