Completed
Push — master ( ca8025...177d87 )
by Łukasz
14:26
created

ViewMatcherRegistryTest::testGetMatcherNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @license For full copyright and license information view LICENSE file distributed with this source code.
4
 */
5
namespace eZ\Bundle\EzPublishCoreBundle\Matcher;
6
7
use eZ\Publish\API\Repository\Exceptions\NotFoundException;
8
use eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MatcherInterface;
9
use PHPUnit\Framework\TestCase;
10
11
class ViewMatcherRegistryTest extends TestCase
12
{
13
    private const MATCHER_NAME = 'test_matcher';
14
15
    public function testGetMatcher(): void
16
    {
17
        $matcher = $this->getMatcherMock();
18
        $registry = new ViewMatcherRegistry([self::MATCHER_NAME => $matcher]);
19
20
        $this->assertSame($matcher, $registry->getMatcher(self::MATCHER_NAME));
21
    }
22
23
    public function testSetMatcher(): void
24
    {
25
        $matcher = $this->getMatcherMock();
26
        $registry = new ViewMatcherRegistry();
27
28
        $registry->setMatcher(self::MATCHER_NAME, $matcher);
29
30
        $this->assertSame($matcher, $registry->getMatcher(self::MATCHER_NAME));
31
    }
32
33
    public function testSetMatcherOverride(): void
34
    {
35
        $matcher = $this->getMatcherMock();
36
        $newMatcher = $this->getMatcherMock();
37
        $registry = new ViewMatcherRegistry([self::MATCHER_NAME, $matcher]);
38
39
        $registry->setMatcher(self::MATCHER_NAME, $newMatcher);
40
41
        $this->assertSame($newMatcher, $registry->getMatcher(self::MATCHER_NAME));
42
    }
43
44
    public function testGetMatcherNotFound(): void
45
    {
46
        $this->expectException(NotFoundException::class);
47
        $registry = new ViewMatcherRegistry();
48
49
        $registry->getMatcher(self::MATCHER_NAME);
50
    }
51
52
    protected function getMatcherMock(): MatcherInterface
53
    {
54
        return $this->createMock(MatcherInterface::class);
55
    }
56
}
57