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

ContentTest::testMatchLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 5
loc 5
rs 10
c 0
b 0
f 0
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\Content as ContentIdMatcher;
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 ContentTest 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\Content */
17
    private $matcher;
18
19
    protected function setUp(): void
20
    {
21
        parent::setUp();
22
        $this->matcher = new ContentIdMatcher();
23
    }
24
25
    /**
26
     * @dataProvider matchLocationProvider
27
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Content::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->generateLocationForContentId(123),
46
                true,
47
            ],
48
            [
49
                123,
50
                $this->generateLocationForContentId(456),
51
                false,
52
            ],
53
            [
54
                [123, 789],
55
                $this->generateLocationForContentId(456),
56
                false,
57
            ],
58
            [
59
                [123, 789],
60
                $this->generateLocationForContentId(789),
61
                true,
62
            ],
63
        ];
64
    }
65
66
    /**
67
     * Generates a Location mock in respect of a given content Id.
68
     *
69
     * @param int $contentId
70
     *
71
     * @return \PHPUnit\Framework\MockObject\MockObject
72
     */
73
    private function generateLocationForContentId($contentId)
74
    {
75
        $location = $this->getLocationMock();
76
        $location
77
            ->expects($this->any())
78
            ->method('getContentInfo')
79
            ->will(
80
                $this->returnValue(
81
                    $this->getContentInfoMock(['id' => $contentId])
82
                )
83
            );
84
85
        return $location;
86
    }
87
88
    /**
89
     * @dataProvider matchContentInfoProvider
90
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\Id\Content::matchContentInfo
91
     * @covers \eZ\Publish\Core\MVC\Symfony\Matcher\ContentBased\MultipleValued::setMatchingConfig
92
     *
93
     * @param int|int[] $matchingConfig
94
     * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
95
     * @param bool $expectedResult
96
     */
97
    public function testMatchContentInfo($matchingConfig, ContentInfo $contentInfo, $expectedResult)
98
    {
99
        $this->matcher->setMatchingConfig($matchingConfig);
100
        $this->assertSame($expectedResult, $this->matcher->matchContentInfo($contentInfo));
101
    }
102
103
    public function matchContentInfoProvider()
104
    {
105
        return [
106
            [
107
                123,
108
                $this->getContentInfoMock(['id' => 123]),
109
                true,
110
            ],
111
            [
112
                123,
113
                $this->getContentInfoMock(['id' => 456]),
114
                false,
115
            ],
116
            [
117
                [123, 789],
118
                $this->getContentInfoMock(['id' => 456]),
119
                false,
120
            ],
121
            [
122
                [123, 789],
123
                $this->getContentInfoMock(['id' => 789]),
124
                true,
125
            ],
126
        ];
127
    }
128
}
129