diff --git a/module/Core/test/Domain/DomainServiceTest.php b/module/Core/test/Domain/DomainServiceTest.php new file mode 100644 index 00000000..e91c3281 --- /dev/null +++ b/module/Core/test/Domain/DomainServiceTest.php @@ -0,0 +1,49 @@ +em = $this->prophesize(EntityManagerInterface::class); + $this->domainService = new DomainService($this->em->reveal()); + } + + /** + * @test + * @dataProvider provideExcludedDomains + */ + public function listDomainsWithoutDelegatesIntoRepository(?string $excludedDomain, array $expectedResult): void + { + $repo = $this->prophesize(DomainRepositoryInterface::class); + $getRepo = $this->em->getRepository(Domain::class)->willReturn($repo->reveal()); + $findDomains = $repo->findDomainsWithout($excludedDomain)->willReturn($expectedResult); + + $result = $this->domainService->listDomainsWithout($excludedDomain); + + self::assertEquals($expectedResult, $result); + $getRepo->shouldHaveBeenCalledOnce(); + $findDomains->shouldHaveBeenCalledOnce(); + } + + public function provideExcludedDomains(): iterable + { + yield 'no excluded domain' => [null, []]; + yield 'foo.com excluded domain' => ['foo.com', []]; + yield 'bar.com excluded domain' => ['bar.com', [new Domain('bar.com')]]; + yield 'baz.com excluded domain' => ['baz.com', [new Domain('foo.com'), new Domain('bar.com')]]; + } +} diff --git a/module/Rest/test/Action/Domain/ListDomainsActionTest.php b/module/Rest/test/Action/Domain/ListDomainsActionTest.php new file mode 100644 index 00000000..fe8ffa07 --- /dev/null +++ b/module/Rest/test/Action/Domain/ListDomainsActionTest.php @@ -0,0 +1,58 @@ +domainService = $this->prophesize(DomainServiceInterface::class); + $this->action = new ListDomainsAction($this->domainService->reveal(), 'foo.com'); + } + + /** @test */ + public function domainsAreProperlyListed(): void + { + $listDomains = $this->domainService->listDomainsWithout('foo.com')->willReturn([ + new Domain('bar.com'), + new Domain('baz.com'), + ]); + + /** @var JsonResponse $resp */ + $resp = $this->action->handle(ServerRequestFactory::fromGlobals()); + $payload = $resp->getPayload(); + + self::assertEquals([ + 'domains' => [ + 'data' => [ + [ + 'domain' => 'foo.com', + 'isDefault' => true, + ], + [ + 'domain' => 'bar.com', + 'isDefault' => false, + ], + [ + 'domain' => 'baz.com', + 'isDefault' => false, + ], + ], + ], + ], $payload); + $listDomains->shouldHaveBeenCalledOnce(); + } +}