SelectorTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 168
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 168
rs 10
c 2
b 0
f 0
wmc 9
lcom 0
cbo 4

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testInvalidIdComponent() 0 4 1
A testFactorySelectors() 0 13 1
B getSelector() 0 45 1
A testFactoryInvalidSelector() 0 4 1
A testInvalidDateComponent() 0 4 1
A testInvalidTypeComponent() 0 7 1
A testInvalidRevisionComponent() 0 8 1
A testInvalidVisibilityComponent() 0 7 1
A testInvalidDraftComponent() 0 7 1
1
<?php
2
3
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Object
8
 * @subpackage  Apparat\Object\Framwork
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Object\Tests;
38
39
use Apparat\Kernel\Ports\Kernel;
40
use Apparat\Object\Domain\Model\Object\Revision;
41
use Apparat\Object\Domain\Repository\Selector;
42
use Apparat\Object\Domain\Repository\Selector as RepositorySelector;
43
use Apparat\Object\Domain\Repository\SelectorInterface;
44
use Apparat\Object\Ports\Factory\SelectorFactory;
45
use Apparat\Object\Ports\Types\Object as ObjectTypes;
46
47
/**
48
 * Selector tests
49
 *
50
 * @package Apparat\Object
51
 * @subpackage Apparat\Object\Test
52
 */
53
class SelectorTest extends AbstractDisabledAutoconnectorTest
54
{
55
    /**
56
     * Test repository selectors
57
     *
58
     * @dataProvider getSelector
59
     * @param string $selector Selector
60
     * @param array $data Data
61
     */
62
    public function testFactorySelectors($selector, array $data)
63
    {
64
        $selector = SelectorFactory::createFromString($selector);
65
        $this->assertInstanceOf(Selector::class, $selector);
66
        $this->assertEquals($data[0], $selector->getYear());
67
        $this->assertEquals($data[1], $selector->getMonth());
68
        $this->assertEquals($data[2], $selector->getDay());
69
        $this->assertEquals($data[3], $selector->getVisibility());
70
        $this->assertEquals($data[4], $selector->getId());
71
        $this->assertEquals($data[5], $selector->getObjectType());
72
        $this->assertEquals($data[6], $selector->getDraft());
73
        $this->assertEquals($data[7], $selector->getRevision());
74
    }
75
76
    /**
77
     * Provide selectors
78
     */
79
    public function getSelector()
80
    {
81
        $wlc = SelectorInterface::WILDCARD;
82
        $vsb = SelectorInterface::VISIBLE;
83
        $pub = SelectorInterface::PUBLISHED;
84
        $all = SelectorInterface::ALL;
85
        $hid = SelectorInterface::HIDDEN;
86
        $dft = SelectorInterface::DRAFT;
87
        $cur = Revision::CURRENT;
88
        return [
89
            ['/2016', ['2016', $wlc, $wlc, $vsb, $wlc, $wlc, $pub, $cur]],
90
            ['/*', [$wlc, $wlc, $wlc, $vsb, $wlc, $wlc, $pub, $cur]],
91
            ['/2016/06', ['2016', '06', $wlc, $vsb, $wlc, $wlc, $pub, $cur]],
92
            ['/2016/*', ['2016', $wlc, $wlc, $vsb, $wlc, $wlc, $pub, $cur]],
93
            ['/2016/06/16', ['2016', '06', '16', $vsb, $wlc, $wlc, $pub, $cur]],
94
            ['/2016/06/*', ['2016', '06', $wlc, $vsb, $wlc, $wlc, $pub, $cur]],
95
            ['/2016/06/16/123', ['2016', '06', '16', $vsb, 123, $wlc, $pub, $cur]],
96
            ['/2016/06/16/.123', ['2016', '06', '16', $hid, 123, $wlc, $pub, $cur]],
97
            ['/2016/06/16/~123', ['2016', '06', '16', $all, 123, $wlc, $pub, $cur]],
98
            ['/2016/06/16/*', ['2016', '06', '16', $vsb, $wlc, $wlc, $pub, $cur]],
99
            ['/2016/06/16/.*', ['2016', '06', '16', $hid, $wlc, $wlc, $pub, $cur]],
100
            ['/2016/06/16/~*', ['2016', '06', '16', $all, $wlc, $wlc, $pub, $cur]],
101
            ['/2016/06/16/123/123', ['2016', '06', '16', $vsb, 123, $wlc, $pub, $cur]],
102
            ['/2016/06/16/123-article', ['2016', '06', '16', $vsb, 123, 'article', $pub, $cur]],
103
            ['/2016/06/16/123-*', ['2016', '06', '16', $vsb, 123, $wlc, $pub, $cur]],
104
            ['/2016/06/16/123-article/123', ['2016', '06', '16', $vsb, 123, 'article', $pub, $cur]],
105
            ['/2016/06/16/123-article/*', ['2016', '06', '16', $vsb, 123, 'article', $pub, $cur]],
106
            ['/2016/06/16/123-article/.123', ['2016', '06', '16', $vsb, 123, 'article', $dft, $cur]],
107
            ['/2016/06/16/123-article/~123', ['2016', '06', '16', $vsb, 123, 'article', $all, $cur]],
108
            ['/2016/06/16/123-article/.*', ['2016', '06', '16', $vsb, 123, 'article', $dft, $cur]],
109
            ['/2016/06/16/123-article/~*', ['2016', '06', '16', $vsb, 123, 'article', $all, $cur]],
110
            ['/2016/06/16/123-article/123-99', ['2016', '06', '16', $vsb, 123, 'article', $pub, 99]],
111
            ['/2016/06/16/123-article/123-*', ['2016', '06', '16', $vsb, 123, 'article', $pub, $wlc]],
112
            ['/2016/06/16/123-article/.123-99', ['2016', '06', '16', $vsb, 123, 'article', $hid, 99]],
113
            ['/2016/06/16/123-article/.123-*', ['2016', '06', '16', $vsb, 123, 'article', $hid, $wlc]],
114
            ['/2016/06/16/123-article/~123-99', ['2016', '06', '16', $vsb, 123, 'article', $all, 99]],
115
            ['/2016/06/16/123-article/~123-*', ['2016', '06', '16', $vsb, 123, 'article', $all, $wlc]],
116
            ['/*/06/16/123-article/123-99', [$wlc, '06', '16', $vsb, 123, 'article', $pub, 99]],
117
            ['/2016/*/16/123-article/123-99', ['2016', $wlc, '16', $vsb, 123, 'article', $pub, 99]],
118
            ['/2016/06/*/123-article/123-99', ['2016', '06', $wlc, $vsb, 123, 'article', $pub, 99]],
119
            ['/2016/06/16/*-article/*-99', ['2016', '06', '16', $vsb, $wlc, 'article', $pub, 99]],
120
            ['/2016/06/16/123-*/123-99', ['2016', '06', '16', $vsb, 123, $wlc, $pub, 99]],
121
            ['/2016/06/16/123-article/*-99', ['2016', '06', '16', $vsb, 123, 'article', $pub, 99]],
122
        ];
123
    }
124
125
    /**
126
     * Test an invalid selector
127
     *
128
     * @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException
129
     * @expectedExceptionCode 1449961609
130
     */
131
    public function testFactoryInvalidSelector()
132
    {
133
        SelectorFactory::createFromString('invalid');
134
    }
135
136
    /**
137
     * Test an invalid date component
138
     *
139
     * @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException
140
     * @expectedExceptionCode 1449999646
141
     * @expectedExceptionMessageRegExp %year%
142
     */
143
    public function testInvalidDateComponent()
144
    {
145
        Kernel::create(RepositorySelector::class, ['invalid']);
146
    }
147
148
    /**
149
     * Test an invalid ID component
150
     *
151
     * @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException
152
     * @expectedExceptionCode 1449999646
153
     * @expectedExceptionMessageRegExp %id%
154
     */
155
    public function testInvalidIdComponent()
156
    {
157
        Kernel::create(RepositorySelector::class, [2015, 1, 1, null, null, null, 'invalid']);
158
    }
159
160
    /**
161
     * Test an invalid type component
162
     *
163
     * @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException
164
     * @expectedExceptionCode 1449999646
165
     * @expectedExceptionMessageRegExp %type%
166
     */
167
    public function testInvalidTypeComponent()
168
    {
169
        Kernel::create(
170
            RepositorySelector::class,
171
            [2015, 1, 1, null, null, null, 1, 'invalid', SelectorInterface::PUBLISHED]
172
        );
173
    }
174
175
    /**
176
     * Test an invalid revision component
177
     *
178
     * @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException
179
     * @expectedExceptionCode 1449999646
180
     * @expectedExceptionMessageRegExp %revision%
181
     */
182
    public function testInvalidRevisionComponent()
183
    {
184
        Kernel::create(
185
            RepositorySelector::class,
186
            [2015, 1, 1, null, null, null, 1, ObjectTypes::ARTICLE, 'invalid', SelectorInterface::VISIBLE,
187
                SelectorInterface::PUBLISHED]
188
        );
189
    }
190
191
    /**
192
     * Test an invalid object visibility
193
     *
194
     * @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException
195
     * @expectedExceptionCode 1449999646
196
     * @expectedExceptionMessageRegExp %visibility%
197
     */
198
    public function testInvalidVisibilityComponent()
199
    {
200
        Kernel::create(
201
            RepositorySelector::class,
202
            [2015, 1, 1, null, null, null, 1, ObjectTypes::ARTICLE, Revision::CURRENT, 0, SelectorInterface::PUBLISHED]
203
        );
204
    }
205
206
    /**
207
     * Test an invalid object draft state
208
     *
209
     * @expectedException \Apparat\Object\Domain\Repository\InvalidArgumentException
210
     * @expectedExceptionCode 1449999646
211
     * @expectedExceptionMessageRegExp %draft%
212
     */
213
    public function testInvalidDraftComponent()
214
    {
215
        Kernel::create(
216
            RepositorySelector::class,
217
            [2015, 1, 1, null, null, null, 1, ObjectTypes::ARTICLE, Revision::CURRENT, SelectorInterface::VISIBLE, 4]
218
        );
219
    }
220
}
221