Completed
Push — master ( 844a18...827038 )
by Joschi
02:54
created

AuxiliaryText::testProvisionalId()   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
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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\Object\Application\Utility\ArrayUtility;
40
use Apparat\Object\Domain\Model\Object\Id;
41
use Apparat\Object\Domain\Model\Object\Revision;
42
use Apparat\Object\Domain\Model\Object\Type;
43
44
/**
45
 * Selector tests
46
 *
47
 * @package Apparat\Object
48
 * @subpackage ApparatTest
49
 */
50
class AuxiliaryText extends AbstractDisabledAutoconnectorTest
51
{
52
    /**
53
     * Test an invalid ID
54
     *
55
     * @expectedException \Apparat\Object\Domain\Model\Object\InvalidArgumentException
56
     * @expectedExceptionCode 1449876361
57
     */
58
    public function testInvalidId()
59
    {
60
        new Id(-1);
61
    }
62
63
    /**
64
     * Test a provisional ID
65
     */
66
    public function testProvisionalId() {
67
        $this->assertTrue((new Id(0))->isProvisional());
68
    }
69
70
    /**
71
     * Test ID serialization
72
     */
73
    public function testIdSerialization()
74
    {
75
        $uid = new Id(123);
76
        $this->assertEquals(123, $uid->serialize());
77
    }
78
79
    /**
80
     * Test an invalid type
81
     *
82
     * @expectedException \Apparat\Object\Domain\Model\Object\InvalidArgumentException
83
     * @expectedExceptionCode 1449871242
84
     */
85
    public function testInvalidType()
86
    {
87
        new Type('invalid');
88
    }
89
90
    /**
91
     * Test type serialization
92
     */
93
    public function testTypeSerialization()
94
    {
95
        $type = new Type(Type::ARTICLE);
96
        $this->assertEquals(Type::ARTICLE, $type->serialize());
97
    }
98
99
    /**
100
     * Test an invalid Revision
101
     *
102
     * @expectedException \Apparat\Object\Domain\Model\Object\InvalidArgumentException
103
     * @expectedExceptionCode 1449871715
104
     */
105
    public function testInvalidRevision()
106
    {
107
        new Revision('abc');
108
    }
109
110
    /**
111
     * Test revision serialization
112
     */
113
    public function testRevisionSerialization()
114
    {
115
        $revision = new Revision(123);
116
        $this->assertEquals(123, $revision->serialize());
117
        $revision = new Revision(Revision::CURRENT);
118
        $this->assertEquals(Revision::CURRENT, $revision->serialize());
119
    }
120
121
    /**
122
     * Test current revision
123
     */
124
    public function testCurrentRevision()
125
    {
126
        $revision = new Revision(Revision::CURRENT);
127
        $this->assertTrue($revision->isCurrent());
128
    }
129
130
    /**
131
     * Test draft revision
132
     */
133
    public function testDraftRevision()
134
    {
135
        $revision = new Revision(Revision::DRAFT);
136
        $this->assertTrue($revision->isDraft());
137
    }
138
139
    /**
140
     * Test a repository invalid argument exception
141
     */
142
    public function testInvalidArgumentException()
143
    {
144
        $exception = new \Apparat\Object\Domain\Repository\InvalidArgumentException('Test', 0, null, 'test');
145
        $this->assertInstanceOf(\Apparat\Object\Domain\Repository\InvalidArgumentException::class, $exception);
146
        $this->assertEquals('test', $exception->getArgumentName());
147
    }
148
149
    /**
150
     * Test recursive array sorting by key
151
     */
152
    public function testSortArrayByKeyRecursively()
153
    {
154
        $unsorted = ['b' => 2, 'a' => ['c' => 3, 'a' => 1]];
155
        $sorted = ['a' => ['a' => 1, 'c' => 3], 'b' => 2];
156
        $this->assertEquals(serialize($sorted), serialize(ArrayUtility::sortRecursiveByKey($unsorted)));
157
    }
158
}
159