From 665f0044cc95a0d7655610a3849c1f99cfa9125a Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Wed, 16 Jan 2019 20:55:49 +0100 Subject: [PATCH] Optimized repository tests --- .../{ => Meta}/RightRepositoryTest.php | 2 +- .../Source/SourceRepositoryTest.php | 50 +++++++++++++++++++ .../{ => Source}/UserSourceRepositoryTest.php | 2 +- 3 files changed, 52 insertions(+), 2 deletions(-) rename application/symfony/tests/Unit/Repository/{ => Meta}/RightRepositoryTest.php (98%) create mode 100644 application/symfony/tests/Unit/Repository/Source/SourceRepositoryTest.php rename application/symfony/tests/Unit/Repository/{ => Source}/UserSourceRepositoryTest.php (98%) diff --git a/application/symfony/tests/Unit/Repository/RightRepositoryTest.php b/application/symfony/tests/Unit/Repository/Meta/RightRepositoryTest.php similarity index 98% rename from application/symfony/tests/Unit/Repository/RightRepositoryTest.php rename to application/symfony/tests/Unit/Repository/Meta/RightRepositoryTest.php index dc9ac26..48abdf9 100644 --- a/application/symfony/tests/Unit/Repository/RightRepositoryTest.php +++ b/application/symfony/tests/Unit/Repository/Meta/RightRepositoryTest.php @@ -1,6 +1,6 @@ getContainer() + ->get('doctrine') + ->getManager(); + $this->sourceRepository = $entityManager->getRepository(AbstractSource::class); + } + + public function testLoadBySlugOrId(): void + { + $requestedSource = $this->createMock(RequestedSourceInterface::class); + $requestedSource->method('hasSlug')->willReturn(true); + $requestedSource->method('getSlug')->willReturn(SystemSlugType::IMPRINT); + $imprint = $this->sourceRepository->findOneByIdOrSlug($requestedSource); + $this->assertInstanceOf(SourceInterface::class, $imprint); + $requestedSource2 = $this->createMock(RequestedSourceInterface::class); + $requestedSource2->method('hasId')->willReturn(true); + $requestedSource2->method('getId')->willReturn($imprint->getId()); + $imprint2 = $this->sourceRepository->findOneByIdOrSlug($requestedSource2); + $this->assertInstanceOf(SourceInterface::class, $imprint2); + } + + public function testLoadBySlug(): void + { + $imprint = $this->sourceRepository->findOneBySlug(SystemSlugType::IMPRINT); + $this->assertInstanceOf(SourceInterface::class, $imprint); + } +} diff --git a/application/symfony/tests/Unit/Repository/UserSourceRepositoryTest.php b/application/symfony/tests/Unit/Repository/Source/UserSourceRepositoryTest.php similarity index 98% rename from application/symfony/tests/Unit/Repository/UserSourceRepositoryTest.php rename to application/symfony/tests/Unit/Repository/Source/UserSourceRepositoryTest.php index abbbe0a..476cd3d 100644 --- a/application/symfony/tests/Unit/Repository/UserSourceRepositoryTest.php +++ b/application/symfony/tests/Unit/Repository/Source/UserSourceRepositoryTest.php @@ -1,6 +1,6 @@