Skip to content

Commit 37571cf

Browse files
author
full
committed
fix tests
1 parent ea47351 commit 37571cf

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

Entity/TokenManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function deleteExpired()
9191
protected function getRepository(): EntityRepository
9292
{
9393
$repository = $this->em->getRepository($this->class);
94-
if(!($repository instanceof EntityRepository)){
94+
if (!($repository instanceof EntityRepository)) {
9595
throw new \RuntimeException('EntityRepository needed');
9696
}
9797

Tests/Entity/TokenManagerTest.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace FOS\OAuthServerBundle\Tests\Entity;
1515

16+
use Doctrine\Common\Persistence\ObjectRepository;
1617
use Doctrine\ORM\AbstractQuery;
1718
use Doctrine\ORM\EntityManager;
1819
use Doctrine\ORM\EntityManagerInterface;
@@ -64,7 +65,6 @@ public function setUp()
6465
;
6566

6667
$this->entityManager
67-
->expects($this->once())
6868
->method('getRepository')
6969
->with($this->className)
7070
->willReturn($this->repository)
@@ -76,7 +76,6 @@ public function setUp()
7676
public function testConstructWillSetParameters()
7777
{
7878
$this->assertAttributeSame($this->entityManager, 'em', $this->instance);
79-
$this->assertAttributeSame($this->repository, 'repository', $this->instance);
8079
$this->assertAttributeSame($this->className, 'class', $this->instance);
8180
}
8281

@@ -228,4 +227,29 @@ public function testDeleteExpired()
228227

229228
$this->assertSame($randomResult, $this->instance->deleteExpired());
230229
}
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+
}
231255
}

0 commit comments

Comments
 (0)