1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ShlinkioTest\Shlink\Core\Domain; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
10
|
|
|
use Shlinkio\Shlink\Core\Domain\DomainService; |
11
|
|
|
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepositoryInterface; |
12
|
|
|
use Shlinkio\Shlink\Core\Entity\Domain; |
13
|
|
|
|
14
|
|
|
class DomainServiceTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
private DomainService $domainService; |
17
|
|
|
private ObjectProphecy $em; |
18
|
|
|
|
19
|
|
|
public function setUp(): void |
20
|
|
|
{ |
21
|
|
|
$this->em = $this->prophesize(EntityManagerInterface::class); |
22
|
|
|
$this->domainService = new DomainService($this->em->reveal()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @test |
27
|
|
|
* @dataProvider provideExcludedDomains |
28
|
|
|
*/ |
29
|
|
|
public function listDomainsWithoutDelegatesIntoRepository(?string $excludedDomain, array $expectedResult): void |
30
|
|
|
{ |
31
|
|
|
$repo = $this->prophesize(DomainRepositoryInterface::class); |
32
|
|
|
$getRepo = $this->em->getRepository(Domain::class)->willReturn($repo->reveal()); |
33
|
|
|
$findDomains = $repo->findDomainsWithout($excludedDomain)->willReturn($expectedResult); |
34
|
|
|
|
35
|
|
|
$result = $this->domainService->listDomainsWithout($excludedDomain); |
36
|
|
|
|
37
|
|
|
self::assertEquals($expectedResult, $result); |
38
|
|
|
$getRepo->shouldHaveBeenCalledOnce(); |
39
|
|
|
$findDomains->shouldHaveBeenCalledOnce(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function provideExcludedDomains(): iterable |
43
|
|
|
{ |
44
|
|
|
yield 'no excluded domain' => [null, []]; |
45
|
|
|
yield 'foo.com excluded domain' => ['foo.com', []]; |
46
|
|
|
yield 'bar.com excluded domain' => ['bar.com', [new Domain('bar.com')]]; |
47
|
|
|
yield 'baz.com excluded domain' => ['baz.com', [new Domain('foo.com'), new Domain('bar.com')]]; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|