diff --git a/module/Core/config/dependencies.config.php b/module/Core/config/dependencies.config.php index f5c75bac..1ef7257c 100644 --- a/module/Core/config/dependencies.config.php +++ b/module/Core/config/dependencies.config.php @@ -16,6 +16,7 @@ return [ Service\VisitsTracker::class => AnnotatedFactory::class, Service\ShortUrlService::class => AnnotatedFactory::class, Service\VisitService::class => AnnotatedFactory::class, + Service\Tag\TagService::class => AnnotatedFactory::class, // Middleware Action\RedirectAction::class => AnnotatedFactory::class, diff --git a/module/Core/src/Service/Tag/TagService.php b/module/Core/src/Service/Tag/TagService.php new file mode 100644 index 00000000..91cb5a72 --- /dev/null +++ b/module/Core/src/Service/Tag/TagService.php @@ -0,0 +1,34 @@ +em = $em; + } + + /** + * @return Tag[] + * @throws \UnexpectedValueException + */ + public function listTags() + { + return $this->em->getRepository(Tag::class)->findBy([], ['name' => 'DESC']); + } +} diff --git a/module/Core/src/Service/Tag/TagServiceInterface.php b/module/Core/src/Service/Tag/TagServiceInterface.php new file mode 100644 index 00000000..cf1914f4 --- /dev/null +++ b/module/Core/src/Service/Tag/TagServiceInterface.php @@ -0,0 +1,12 @@ +em = $this->prophesize(EntityManagerInterface::class); + $this->service = new TagService($this->em->reveal()); + } + + /** + * @test + */ + public function listTagsDelegatesOnRepository() + { + $expected = [new Tag(), new Tag()]; + + $repo = $this->prophesize(EntityRepository::class); + /** @var MethodProphecy $find */ + $find = $repo->findBy(Argument::cetera())->willReturn($expected); + /** @var MethodProphecy $getRepo */ + $getRepo = $this->em->getRepository(Tag::class)->willReturn($repo->reveal()); + + $result = $this->service->listTags(); + + $this->assertEquals($expected, $result); + $find->shouldHaveBeenCalled(); + $getRepo->shouldHaveBeenCalled(); + } +}