Skip to content

Commit 24c2595

Browse files
committed
Update Client Manager
1 parent b1271e1 commit 24c2595

File tree

4 files changed

+9
-45
lines changed

4 files changed

+9
-45
lines changed

Entity/ClientManager.php

+8-11
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,14 @@ class ClientManager extends BaseClientManager
2525
*/
2626
protected $em;
2727

28-
/**
29-
* @var EntityRepository
30-
*/
31-
protected $repository;
32-
3328
/**
3429
* @var string
3530
*/
3631
protected $class;
3732

3833
public function __construct(EntityManagerInterface $em, $class)
3934
{
40-
// NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected
41-
/** @var EntityRepository $repository */
42-
$repository = $em->getRepository($class);
43-
4435
$this->em = $em;
45-
$this->repository = $repository;
4636
$this->class = $class;
4737
}
4838

@@ -59,7 +49,7 @@ public function getClass()
5949
*/
6050
public function findClientBy(array $criteria)
6151
{
62-
return $this->repository->findOneBy($criteria);
52+
return $this->getRepository()->findOneBy($criteria);
6353
}
6454

6555
/**
@@ -79,4 +69,11 @@ public function deleteClient(ClientInterface $client)
7969
$this->em->remove($client);
8070
$this->em->flush();
8171
}
72+
73+
private function getRepository(): EntityRepository
74+
{
75+
$repository = $this->em->getRepository($this->class);
76+
77+
return $repository;
78+
}
8279
}

Entity/TokenManager.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,9 @@ public function deleteExpired()
8585
return $qb->getQuery()->execute();
8686
}
8787

88-
/**
89-
* @return EntityRepository
90-
*/
91-
protected function getRepository(): EntityRepository
88+
private function getRepository(): EntityRepository
9289
{
9390
$repository = $this->em->getRepository($this->class);
94-
if (!($repository instanceof EntityRepository)) {
95-
throw new \RuntimeException('EntityRepository needed');
96-
}
9791

9892
return $repository;
9993
}

Tests/Entity/ClientManagerTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public function setUp()
5858
$this->className = 'RandomClassName'.\random_bytes(5);
5959

6060
$this->entityManager
61-
->expects($this->once())
6261
->method('getRepository')
6362
->with($this->className)
6463
->willReturn($this->repository)
@@ -72,7 +71,6 @@ public function setUp()
7271
public function testConstructWillSetParameters()
7372
{
7473
$this->assertAttributeSame($this->entityManager, 'em', $this->instance);
75-
$this->assertAttributeSame($this->repository, 'repository', $this->instance);
7674
$this->assertAttributeSame($this->className, 'class', $this->instance);
7775
}
7876

Tests/Entity/TokenManagerTest.php

-25
Original file line numberDiff line numberDiff line change
@@ -227,29 +227,4 @@ public function testDeleteExpired()
227227

228228
$this->assertSame($randomResult, $this->instance->deleteExpired());
229229
}
230-
231-
public function testExceptionWithObjectRepository()
232-
{
233-
$this->repository = $this->getMockBuilder(ObjectRepository::class)
234-
->disableOriginalConstructor()
235-
->getMock()
236-
;
237-
238-
$this->entityManager = $this->getMockBuilder(EntityManager::class)
239-
->disableOriginalConstructor()
240-
->getMock()
241-
;
242-
243-
$this->entityManager
244-
->expects($this->once())
245-
->method('getRepository')
246-
->with($this->className)
247-
->willReturn($this->repository)
248-
;
249-
250-
$this->instance = new TokenManager($this->entityManager, $this->className);
251-
252-
$this->expectException(\RuntimeException::class);
253-
$this->instance->findTokenBy([]);
254-
}
255230
}

0 commit comments

Comments
 (0)