Completed
Push — master ( ff8f52...ed8581 )
by
unknown
12:31 queued 10s
created

SiteAccessMatcherRegistryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetMatcher() 0 7 1
A testSetMatcher() 0 9 1
A testSetMatcherOverride() 0 10 1
A testGetMatcherNotFound() 0 7 1
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace eZ\Bundle\EzPublishCoreBundle\Tests\SiteAccess;
10
11
use eZ\Bundle\EzPublishCoreBundle\SiteAccess\Matcher;
12
use eZ\Bundle\EzPublishCoreBundle\SiteAccess\SiteAccessMatcherRegistry;
13
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
14
use PHPUnit\Framework\TestCase;
15
16
class SiteAccessMatcherRegistryTest extends TestCase
17
{
18
    private const MATCHER_NAME = 'test_matcher';
19
20
    public function testGetMatcher(): void
21
    {
22
        $matcher = $this->getMatcherMock();
23
        $registry = new SiteAccessMatcherRegistry([self::MATCHER_NAME => $matcher]);
24
25
        $this->assertSame($matcher, $registry->getMatcher(self::MATCHER_NAME));
26
    }
27
28
    public function testSetMatcher(): void
29
    {
30
        $matcher = $this->getMatcherMock();
31
        $registry = new SiteAccessMatcherRegistry();
32
33
        $registry->setMatcher(self::MATCHER_NAME, $matcher);
34
35
        $this->assertSame($matcher, $registry->getMatcher(self::MATCHER_NAME));
36
    }
37
38
    public function testSetMatcherOverride(): void
39
    {
40
        $matcher = $this->getMatcherMock();
41
        $newMatcher = $this->getMatcherMock();
42
        $registry = new SiteAccessMatcherRegistry([self::MATCHER_NAME, $matcher]);
43
44
        $registry->setMatcher(self::MATCHER_NAME, $newMatcher);
45
46
        $this->assertSame($newMatcher, $registry->getMatcher(self::MATCHER_NAME));
47
    }
48
49
    public function testGetMatcherNotFound(): void
50
    {
51
        $this->expectException(NotFoundException::class);
52
        $registry = new SiteAccessMatcherRegistry();
53
54
        $registry->getMatcher(self::MATCHER_NAME);
55
    }
56
57
    protected function getMatcherMock(): Matcher
58
    {
59
        return $this->createMock(Matcher::class);
60
    }
61
}
62