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

ViewMatcherRegistryTest   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

5 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
A getMatcherMock() 0 4 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
namespace eZ\Bundle\EzPublishCoreBundle\Tests\Matcher;
8
9
use eZ\Bundle\EzPublishCoreBundle\Matcher\ViewMatcherRegistry;
10
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
11
use eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MatcherInterface;
12
use PHPUnit\Framework\TestCase;
13
14
class ViewMatcherRegistryTest extends TestCase
15
{
16
    private const MATCHER_NAME = 'test_matcher';
17
18
    public function testGetMatcher(): void
19
    {
20
        $matcher = $this->getMatcherMock();
21
        $registry = new ViewMatcherRegistry([self::MATCHER_NAME => $matcher]);
22
23
        $this->assertSame($matcher, $registry->getMatcher(self::MATCHER_NAME));
24
    }
25
26
    public function testSetMatcher(): void
27
    {
28
        $matcher = $this->getMatcherMock();
29
        $registry = new ViewMatcherRegistry();
30
31
        $registry->setMatcher(self::MATCHER_NAME, $matcher);
32
33
        $this->assertSame($matcher, $registry->getMatcher(self::MATCHER_NAME));
34
    }
35
36
    public function testSetMatcherOverride(): void
37
    {
38
        $matcher = $this->getMatcherMock();
39
        $newMatcher = $this->getMatcherMock();
40
        $registry = new ViewMatcherRegistry([self::MATCHER_NAME, $matcher]);
41
42
        $registry->setMatcher(self::MATCHER_NAME, $newMatcher);
43
44
        $this->assertSame($newMatcher, $registry->getMatcher(self::MATCHER_NAME));
45
    }
46
47
    public function testGetMatcherNotFound(): void
48
    {
49
        $this->expectException(NotFoundException::class);
50
        $registry = new ViewMatcherRegistry();
51
52
        $registry->getMatcher(self::MATCHER_NAME);
53
    }
54
55
    protected function getMatcherMock(): MatcherInterface
56
    {
57
        return $this->createMock(MatcherInterface::class);
58
    }
59
}
60