Completed
Push — EZP-31460 ( fb49b1...efa331 )
by
unknown
19:23 queued 11s
created

MatcherSerializationTest::deserializeMatcher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 8
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\SiteAccess\Tests;
8
9
use eZ\Publish\Core\MVC\Symfony\Component\Serializer\SerializerTrait;
10
use eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher;
11
use PHPUnit\Framework\TestCase;
12
13
class MatcherSerializationTest extends TestCase
14
{
15
    use SerializerTrait;
16
17
    /**
18
     * @dataProvider matcherProvider
19
     */
20
    public function testDeserialize(Matcher $matcher)
21
    {
22
        $serializedMatcher = $this->serializeMatcher($matcher);
23
        $unserializedMatcher = $this->deserializeMatcher($serializedMatcher, get_class($matcher));
24
25
        $this->assertEquals($matcher, $unserializedMatcher);
26
    }
27
28
    /**
29
     * @param \eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher $matcher
30
     *
31
     * @return string
32
     */
33
    private function serializeMatcher(Matcher $matcher)
34
    {
35
        return $this->getSerializer()->serialize(
36
            $matcher,
37
            'json'
38
        );
39
    }
40
41
    /**
42
     * @param string $serializedMatcher
43
     * @param string $matcherFQCN
44
     *
45
     * @return \eZ\Publish\Core\MVC\Symfony\SiteAccess\Matcher|object
46
     */
47
    private function deserializeMatcher($serializedMatcher, $matcherFQCN)
48
    {
49
        return $this->getSerializer()->deserialize(
50
            $serializedMatcher,
51
            $matcherFQCN,
52
            'json'
53
        );
54
    }
55
56
    public function matcherProvider()
57
    {
58
        return [
59
            'URIText' => [
60
                new Matcher\URIText([
61
                    'prefix' => 'foo',
62
                    'suffix' => 'bar',
63
                ]),
64
            ],
65
            'HostText' => [
66
                new Matcher\HostText([
67
                    'prefix' => 'foo',
68
                    'suffix' => 'bar',
69
                ]),
70
            ],
71
            'RegexHost' => [
72
                new Matcher\Regex\Host([
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\MVC\Symf...cess\Matcher\Regex\Host has been deprecated with message: since 5.3 as it cannot be reverted.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
73
                    'regex' => 'foo',
74
                    'itemNumber' => 2,
75
                ]),
76
            ],
77
            'RegexURI' => [
78
                new Matcher\Regex\URI([
0 ignored issues
show
Deprecated Code introduced by
The class eZ\Publish\Core\MVC\Symf...ccess\Matcher\Regex\URI has been deprecated with message: since 5.3 as it cannot be reverted.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
79
                    'regex' => 'foo',
80
                    'itemNumber' => 2,
81
                ]),
82
            ],
83
            'URIElement' => [
84
                new Matcher\URIElement([
85
                    'elementNumber' => 2,
86
                ]),
87
            ],
88
            'HostElement' => [
89
                new Matcher\HostElement([
90
                    'elementNumber' => 2,
91
                ]),
92
            ],
93
            'MapURI' => [
94
                new Matcher\Map\URI([
95
                    'map' => ['key' => 'value'],
96
                ]),
97
            ],
98
            'MapPort' => [
99
                new Matcher\Map\Port([
100
                    'map' => ['key' => 'value'],
101
                ]),
102
            ],
103
            'MapHost' => [
104
                new Matcher\Map\Host([
105
                    'map' => ['key' => 'value'],
106
                ]),
107
            ],
108
            'CompoundAnd' => [
109
                new Matcher\Compound\LogicalAnd(
110
                    [
111
                        [
112
                            'matchers' => [
113
                                'Map\URI' => [
114
                                    'map' => ['key' => 'value'],
115
                                ],
116
                                'Map\Host' => [
117
                                    'map' => ['key' => 'value'],
118
                                ],
119
                            ],
120
                            'match' => 'site_access_name',
121
                        ],
122
                    ]
123
                ),
124
            ],
125
            'CompoundOr' => [
126
                new Matcher\Compound\LogicalOr(
127
                    [
128
                        [
129
                            'matchers' => [
130
                                'Map\URI' => [
131
                                    'map' => ['key' => 'value'],
132
                                ],
133
                                'Map\Host' => [
134
                                    'map' => ['key' => 'value'],
135
                                ],
136
                            ],
137
                            'match' => 'site_access_name',
138
                        ],
139
                    ]
140
                ),
141
            ],
142
        ];
143
    }
144
}
145