Completed
Push — develop ( 8109ce...b15e90 )
by Alejandro
17s queued 12s
created

listDomainsWithoutDelegatesIntoRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 11
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 2
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