Passed
Push — develop ( 0f0df6...f6c549 )
by Joris van de
46s queued 10s
created

IdentifierMappingTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace FH\Bundle\MultiSiteBundle\Tests\Site;
5
6
use FH\Bundle\MultiSiteBundle\Site\IdentifierMapping;
7
use PHPUnit\Framework\TestCase;
8
9
final class IdentifierMappingTest extends TestCase
10
{
11
    private const MAPPING = [
12
        'amsterdam' => [
13
            'hostnames' => [
14
                'amsterdam.local',
15
                'amsterdam.nl'
16
            ],
17
            'locales' => ['nl', 'en']
18
        ],
19
        'tilburg' => [
20
            'hostnames' => [
21
                'tilburg.local',
22
                'tilburg.nl'
23
            ],
24
            'locales' => ['nl']
25
        ],
26
        'den-bosch' => [
27
            'hostnames' => [
28
                'den-bosch.local',
29
                'den-bosch.nl'
30
            ],
31
            'locales' => []
32
        ]
33
    ];
34
35
    /**
36
     * @var IdentifierMapping
37
     */
38
    private $identifierMapping;
39
40
    protected function setUp()
41
    {
42
        $this->identifierMapping = new IdentifierMapping(self::MAPPING);
43
    }
44
45
    /**
46
     * @dataProvider identifierMappingData
47
     * @param string $hostname
48
     * @param string|null $expectedIdentifier
49
     */
50
    public function testFindIdentifierByHostnameReturnsCorrectIdentifier(string $hostname, string $expectedIdentifier = null): void
51
    {
52
        $identifier = $this->identifierMapping->findIdentifierByHostname($hostname);
53
54
        $this->assertEquals($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->assertEquals($item['hostnames'], $this->identifierMapping->findHostnamesByIdentifier($identifier));
66
        }
67
    }
68
69
    public function testFindHostnamesByIdentifierWithLocaleReturnsCorrectHostnames(): void
70
    {
71
        $hostnames = $this->identifierMapping->findHostnamesByIdentifier('amsterdam', 'nl');
72
        $this->assertEquals(self::MAPPING['amsterdam']['hostnames'], $hostnames);
73
74
        $hostnames = $this->identifierMapping->findHostnamesByIdentifier('amsterdam', 'en');
75
        $this->assertEquals(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