Skip to content

Commit 6975461

Browse files
committed
Ontheflyrepo for Document as well
Replicated the modifications from Entity
1 parent 4b2db2d commit 6975461

File tree

4 files changed

+24
-40
lines changed

4 files changed

+24
-40
lines changed

Document/ClientManager.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace FOS\OAuthServerBundle\Document;
1515

1616
use Doctrine\ODM\MongoDB\DocumentManager;
17-
use Doctrine\ODM\MongoDB\DocumentRepository;
1817
use FOS\OAuthServerBundle\Model\ClientInterface;
1918
use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager;
2019

@@ -25,24 +24,14 @@ class ClientManager extends BaseClientManager
2524
*/
2625
protected $dm;
2726

28-
/**
29-
* @var DocumentRepository
30-
*/
31-
protected $repository;
32-
3327
/**
3428
* @var string
3529
*/
3630
protected $class;
3731

3832
public function __construct(DocumentManager $dm, $class)
3933
{
40-
// NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected
41-
/** @var DocumentRepository $repository */
42-
$repository = $dm->getRepository($class);
43-
4434
$this->dm = $dm;
45-
$this->repository = $repository;
4635
$this->class = $class;
4736
}
4837

@@ -59,7 +48,7 @@ public function getClass()
5948
*/
6049
public function findClientBy(array $criteria)
6150
{
62-
return $this->repository->findOneBy($criteria);
51+
return $this->dm->getRepository($this->class)->findOneBy($criteria);
6352
}
6453

6554
/**

Document/TokenManager.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
namespace FOS\OAuthServerBundle\Document;
1515

1616
use Doctrine\ODM\MongoDB\DocumentManager;
17-
use Doctrine\ODM\MongoDB\DocumentRepository;
1817
use FOS\OAuthServerBundle\Model\TokenInterface;
1918
use FOS\OAuthServerBundle\Model\TokenManager as BaseTokenManager;
2019

@@ -25,24 +24,14 @@ class TokenManager extends BaseTokenManager
2524
*/
2625
protected $dm;
2726

28-
/**
29-
* @var DocumentRepository
30-
*/
31-
protected $repository;
32-
3327
/**
3428
* @var string
3529
*/
3630
protected $class;
3731

3832
public function __construct(DocumentManager $dm, $class)
3933
{
40-
// NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected
41-
/** @var DocumentRepository $repository */
42-
$repository = $dm->getRepository($class);
43-
4434
$this->dm = $dm;
45-
$this->repository = $repository;
4635
$this->class = $class;
4736
}
4837

@@ -59,7 +48,7 @@ public function getClass()
5948
*/
6049
public function findTokenBy(array $criteria)
6150
{
62-
return $this->repository->findOneBy($criteria);
51+
return $this->dm->getRepository($this->class)->findOneBy($criteria);
6352
}
6453

6554
/**
@@ -86,7 +75,7 @@ public function deleteToken(TokenInterface $token)
8675
public function deleteExpired()
8776
{
8877
$result = $this
89-
->repository
78+
->dm->getRepository($this->class)
9079
->createQueryBuilder()
9180
->remove()
9281
->field('expiresAt')->lt(time())

Tests/Document/ClientManagerTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ public function setUp()
6161
;
6262
$this->className = 'RandomClassName'.\random_bytes(5);
6363

64-
$this->documentManager
65-
->expects($this->once())
66-
->method('getRepository')
67-
->with($this->className)
68-
->willReturn($this->repository)
69-
;
70-
7164
$this->instance = new ClientManager($this->documentManager, $this->className);
7265

7366
parent::setUp();
@@ -76,7 +69,6 @@ public function setUp()
7669
public function testConstructWillSetParameters()
7770
{
7871
$this->assertAttributeSame($this->documentManager, 'dm', $this->instance);
79-
$this->assertAttributeSame($this->repository, 'repository', $this->instance);
8072
$this->assertAttributeSame($this->className, 'class', $this->instance);
8173
}
8274

@@ -92,6 +84,13 @@ public function testFindClientBy()
9284
\random_bytes(5),
9385
];
9486

87+
$this->documentManager
88+
->expects($this->once())
89+
->method('getRepository')
90+
->with($this->className)
91+
->willReturn($this->repository)
92+
;
93+
9594
$this->repository
9695
->expects($this->once())
9796
->method('findOneBy')

Tests/Document/TokenManagerTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ public function setUp()
6565
->getMock()
6666
;
6767

68-
$this->documentManager
69-
->expects($this->once())
70-
->method('getRepository')
71-
->with($this->className)
72-
->willReturn($this->repository)
73-
;
74-
7568
$this->instance = new TokenManager($this->documentManager, $this->className);
7669
}
7770

@@ -80,6 +73,13 @@ public function testFindTokenByToken()
8073
$randomToken = \random_bytes(5);
8174
$randomResult = \random_bytes(5);
8275

76+
$this->documentManager
77+
->expects($this->once())
78+
->method('getRepository')
79+
->with($this->className)
80+
->willReturn($this->repository)
81+
;
82+
8383
$this->repository
8484
->expects($this->once())
8585
->method('findOneBy')
@@ -145,6 +145,13 @@ public function testDeleteToken()
145145

146146
public function testDeleteExpired()
147147
{
148+
$this->documentManager
149+
->expects($this->once())
150+
->method('getRepository')
151+
->with($this->className)
152+
->willReturn($this->repository)
153+
;
154+
148155
$queryBuilder = $this->getMockBuilder(Builder::class)
149156
->disableOriginalConstructor()
150157
->getMock()

0 commit comments

Comments
 (0)