IdentifierMappingTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 39
c 1
b 0
f 0
dl 0
loc 86
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testFindHostnamesByIdentifierWithLocaleReturnsCorrectHostnames() 0 13 1
A testFindHostnamesByIdentifierReturnsEmptyHostnamesOnNonExistentIdentifier() 0 4 1
A testFindIdentifierByHostnameReturnsCorrectIdentifier() 0 5 1
A identifierMappingData() 0 7 1
A testFindIdentifierByHostnameReturnsNullWhenNoIdentifierMatches() 0 3 1
A testFindHostnamesByIdentifierWithoutLocaleReturnsCorrectHostnames() 0 4 2
A setUp() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FH\Bundle\MultiSiteBundle\Tests\Site;
6
7
use FH\Bundle\MultiSiteBundle\Site\IdentifierMapping;
8
use FH\Bundle\MultiSiteBundle\Site\IdentifierMappingInterface;
9
use PHPUnit\Framework\TestCase;
10
11
final class IdentifierMappingTest extends TestCase
12
{
13
    private const MAPPING = [
14
        'amsterdam' => [
15
            'hostnames' => [
16
                'amsterdam.local',
17
                'amsterdam.nl',
18
            ],
19
            'locales' => ['nl', 'en'],
20
        ],
21
        'tilburg' => [
22
            'hostnames' => [
23
                'tilburg.local',
24
                'tilburg.nl',
25
            ],
26
            'locales' => ['nl'],
27
        ],
28
        'den-bosch' => [
29
            'hostnames' => [
30
                'den-bosch.local',
31
                'den-bosch.nl',
32
            ],
33
            'locales' => [],
34
        ],
35
    ];
36
37
    /**
38
     * @var IdentifierMappingInterface
39
     */
40
    private $identifierMapping;
41
42
    protected function setUp(): void
43
    {
44
        $this->identifierMapping = new IdentifierMapping(self::MAPPING);
45
    }
46
47
    /**
48
     * @dataProvider identifierMappingData
49
     */
50
    public function testFindIdentifierByHostnameReturnsCorrectIdentifier(string $hostname, ?string $expectedIdentifier = null): void
51
    {
52
        $identifier = $this->identifierMapping->findIdentifierByHostname($hostname);
53
54
        $this->assertSame($expectedIdentifier, $identifier);
55
    }
56
57
    public function testFindIdentifierByHostnameReturnsNullWhenNoIdentifierMatches(): void
58
    {
59
        $this->assertNull($this->identifierMapping->findIdentifierByHostname('xxxx.xxx'));
60
    }
61
62
    public function testFindHostnamesByIdentifierWithoutLocaleReturnsCorrectHostnames(): void
63
    {
64
        foreach (self::MAPPING as $identifier => $item) {
65
            $this->assertSame($item['hostnames'], $this->identifierMapping->findHostnamesByIdentifier($identifier));
66
        }
67
    }
68
69
    public function testFindHostnamesByIdentifierWithLocaleReturnsCorrectHostnames(): void
70
    {
71
        $hostnames = $this->identifierMapping->findHostnamesByIdentifier('amsterdam', 'nl');
72
        $this->assertSame(self::MAPPING['amsterdam']['hostnames'], $hostnames);
73
74
        $hostnames = $this->identifierMapping->findHostnamesByIdentifier('amsterdam', 'en');
75
        $this->assertSame(self::MAPPING['amsterdam']['hostnames'], $hostnames);
76
77
        $hostnames = $this->identifierMapping->findHostnamesByIdentifier('tilburg', 'en');
78
        $this->assertEmpty($hostnames);
79
80
        $hostnames = $this->identifierMapping->findHostnamesByIdentifier('den-bosch', 'nl');
81
        $this->assertEmpty($hostnames);
82
    }
83
84
    public function testFindHostnamesByIdentifierReturnsEmptyHostnamesOnNonExistentIdentifier(): void
85
    {
86
        $hostnames = $this->identifierMapping->findHostnamesByIdentifier('xxxx');
87
        $this->assertEmpty($hostnames);
88
    }
89
90
    public function identifierMappingData(): array
91
    {
92
        return [
93
            ['amsterdam.local', 'amsterdam'],
94
            ['amsterdam.nl', 'amsterdam'],
95
            ['tilburg.local', 'tilburg'],
96
            ['tilburg.nl', 'tilburg'],
97
        ];
98
    }
99
}
100