Completed
Push — EZP-31287 ( fe8c5c...af9523 )
by
unknown
34:01
created

LocationTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 5 5 1
A testMatchLocation() 5 5 1
A matchLocationProvider() 25 25 1
A testMatchContentInfo() 5 5 1
A matchContentInfoProvider() 25 25 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\Publish\Core\MVC\Symfony\Matcher\Tests\ContentBased\Id;
8
9
use eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Location as LocationIdMatcher;
10
use eZ\Publish\API\Repository\Values\Content\Location;
11
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
12
use eZ\Publish\Core\MVC\Symfony\Matcher\Tests\ContentBased\BaseTest;
13
14 View Code Duplication
class LocationTest extends BaseTest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    /** @var \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Location */
17
    private $matcher;
18
19
    protected function setUp()
20
    {
21
        parent::setUp();
22
        $this->matcher = new LocationIdMatcher();
23
    }
24
25
    /**
26
     * @dataProvider matchLocationProvider
27
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Location::matchLocation
28
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig
29
     *
30
     * @param int|int[] $matchingConfig
31
     * @param \eZ\Publish\API\Repository\Values\Content\Location $location
32
     * @param bool $expectedResult
33
     */
34
    public function testMatchLocation($matchingConfig, Location $location, $expectedResult)
35
    {
36
        $this->matcher->setMatchingConfig($matchingConfig);
37
        $this->assertSame($expectedResult, $this->matcher->matchLocation($location));
38
    }
39
40
    public function matchLocationProvider()
41
    {
42
        return [
43
            [
44
                123,
45
                $this->getLocationMock(['id' => 123]),
46
                true,
47
            ],
48
            [
49
                123,
50
                $this->getLocationMock(['id' => 456]),
51
                false,
52
            ],
53
            [
54
                [123, 789],
55
                $this->getLocationMock(['id' => 456]),
56
                false,
57
            ],
58
            [
59
                [123, 789],
60
                $this->getLocationMock(['id' => 789]),
61
                true,
62
            ],
63
        ];
64
    }
65
66
    /**
67
     * @dataProvider matchContentInfoProvider
68
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Location::matchContentInfo
69
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig
70
     *
71
     * @param int|int[] $matchingConfig
72
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
73
     * @param bool $expectedResult
74
     */
75
    public function testMatchContentInfo($matchingConfig, ContentInfo $contentInfo, $expectedResult)
76
    {
77
        $this->matcher->setMatchingConfig($matchingConfig);
78
        $this->assertSame($expectedResult, $this->matcher->matchContentInfo($contentInfo));
79
    }
80
81
    public function matchContentInfoProvider()
82
    {
83
        return [
84
            [
85
                123,
86
                $this->getContentInfoMock(['mainLocationId' => 123]),
87
                true,
88
            ],
89
            [
90
                123,
91
                $this->getContentInfoMock(['mainLocationId' => 456]),
92
                false,
93
            ],
94
            [
95
                [123, 789],
96
                $this->getContentInfoMock(['mainLocationId' => 456]),
97
                false,
98
            ],
99
            [
100
                [123, 789],
101
                $this->getContentInfoMock(['mainLocationId' => 789]),
102
                true,
103
            ],
104
        ];
105
    }
106
}
107