Completed
Push — master ( 61f16c...a373f3 )
by Joschi
03:28
created

AuxiliaryText::testAdapterStrategyInvalidType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\Application\Utility\ArrayUtility;
41
use Apparat\Object\Domain\Model\Object\Id;
42
use Apparat\Object\Domain\Model\Object\Revision;
43
use Apparat\Object\Domain\Model\Object\Type;
44
use Apparat\Object\Infrastructure\Factory\AdapterStrategyFactory;
45
use Apparat\Object\Infrastructure\Repository\FileAdapterStrategy;
46
use Apparat\Object\Ports\Types\Object as ObjectTypes;
47
48
/**
49
 * Selector tests
50
 *
51
 * @package Apparat\Object
52
 * @subpackage Apparat\Object\Test
53
 */
54
class AuxiliaryText extends AbstractDisabledAutoconnectorTest
55
{
56
    /**
57
     * Test an invalid ID
58
     *
59
     * @expectedException \Apparat\Object\Domain\Model\Object\InvalidArgumentException
60
     * @expectedExceptionCode 1449876361
61
     */
62
    public function testInvalidId()
63
    {
64
        new Id(0);
65
    }
66
67
    /**
68
     * Test ID serialization
69
     */
70
    public function testIdSerialization()
71
    {
72
        $uid = new Id(123);
73
        $this->assertEquals(123, $uid->serialize());
74
    }
75
76
    /**
77
     * Test an invalid type
78
     *
79
     * @expectedException \Apparat\Object\Domain\Model\Object\InvalidArgumentException
80
     * @expectedExceptionCode 1449871242
81
     */
82
    public function testInvalidType()
83
    {
84
        Kernel::create(Type::class, ['invalid']);
85
    }
86
87
    /**
88
     * Test type serialization
89
     */
90
    public function testTypeSerialization()
91
    {
92
        $type = Kernel::create(Type::class, [ObjectTypes::ARTICLE]);
93
        $this->assertEquals(ObjectTypes::ARTICLE, $type->serialize());
94
    }
95
96
    /**
97
     * Test an invalid Revision
98
     *
99
     * @expectedException \Apparat\Object\Domain\Model\Object\InvalidArgumentException
100
     * @expectedExceptionCode 1449871715
101
     */
102
    public function testInvalidRevision()
103
    {
104
        new Revision('abc');
105
    }
106
107
    /**
108
     * Test revision serialization
109
     */
110
    public function testRevisionSerialization()
111
    {
112
        $revision = new Revision(123);
113
        $this->assertEquals(123, $revision->serialize());
114
        $revision = Revision::current();
115
        $this->assertEquals(Revision::CURRENT, $revision->serialize());
116
    }
117
118
    /**
119
     * Test current revision
120
     */
121
    public function testCurrentRevision()
122
    {
123
        $revision = Revision::current();
124
        $this->assertTrue($revision->isCurrent());
125
    }
126
127
    /**
128
     * Test a repository invalid argument exception
129
     */
130
    public function testInvalidArgumentException()
131
    {
132
        $exception = new \Apparat\Object\Domain\Repository\InvalidArgumentException('Test', 0, null, 'test');
133
        $this->assertInstanceOf(\Apparat\Object\Domain\Repository\InvalidArgumentException::class, $exception);
134
        $this->assertEquals('test', $exception->getArgumentName());
135
    }
136
137
    /**
138
     * Test recursive array sorting by key
139
     */
140
    public function testSortArrayByKeyRecursively()
141
    {
142
        $unsorted = ['b' => 2, 'a' => ['c' => 3, 'a' => 1]];
143
        $sorted = ['a' => ['a' => 1, 'c' => 3], 'b' => 2];
144
        $this->assertEquals(serialize($sorted), serialize(ArrayUtility::sortRecursiveByKey($unsorted)));
145
    }
146
147
    /**
148
     * Test the reduction of arrays
149
     */
150
    public function testReduceArray()
151
    {
152
        $object = new \stdClass();
153
        $this->assertEquals(
154
            ArrayUtility::reduce([1, 2, 'test', $object, false]),
155
            ArrayUtility::reduce([null, 2, $object, 1, 'test'])
156
        );
157
        $this->assertEquals(
158
            ArrayUtility::reduce(['one' => true, 'two' => [1, 2, 'three']]),
159
            ArrayUtility::reduce(['two' => ['three', 1, 2], 'one' => true])
160
        );
161
    }
162
163
    /**
164
     * Test an invalid adapter strategy type
165
     *
166
     * @expectedException \Apparat\Object\Infrastructure\Factory\InvalidArgumentException
167
     * @expectedExceptionCode 1449956471
168
     */
169
    public function testAdapterStrategyInvalidType() {
170
        AdapterStrategyFactory::setAdapterStrategyTypeClass('', '');
171
    }
172
173
    /**
174
     * Test an invalid adapter strategy class
175
     *
176
     * @expectedException \Apparat\Object\Infrastructure\Factory\InvalidArgumentException
177
     * @expectedExceptionCode 1466883683
178
     */
179
    public function testAdapterStrategyInvalidClass() {
180
        AdapterStrategyFactory::setAdapterStrategyTypeClass(FileAdapterStrategy::TYPE, static::class);
181
    }
182
}
183