DomainServiceTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 17
dl 0
loc 36
rs 10
c 1
b 0
f 0

3 Methods

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