SystemPropertiesTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 5
Bugs 0 Features 0
Metric Value
dl 0
loc 71
rs 10
c 5
b 0
f 0
wmc 3
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSystemProperties() 0 19 1
A testInvalidSystemProperties() 0 6 1
A testObjectSetLocation() 0 16 1
1
<?php
2
3
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Object
8
 * @subpackage  Apparat\Object\Test
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\Model\Object\Article;
40
use Apparat\Object\Domain\Model\Object\AbstractObject;
41
use Apparat\Object\Domain\Model\Object\ObjectInterface;
42
use Apparat\Object\Domain\Model\Properties\SystemProperties;
43
use Apparat\Object\Infrastructure\Model\Object\Object;
44
45
/**
46
 * System properties test
47
 *
48
 * @package Apparat\Object
49
 * @subpackage Apparat\Object\Tests
50
 */
51
class SystemPropertiesTest extends AbstractRepositoryEnabledTest
52
{
53
    /**
54
     * Example object locator
55
     *
56
     * @var string
57
     */
58
    const OBJECT_LOCATOR = '/2015/12/21/1-article/1';
59
60
    /**
61
     * Test the instantiation of system properties
62
     *
63
     * @expectedException \Apparat\Object\Domain\Model\Object\RuntimeException
64
     * @expectedExceptionCode 1456520791
65
     */
66
    public function testSystemProperties()
67
    {
68
        $now = new \DateTimeImmutable('now');
69
        $data = [
70
            SystemProperties::PROPERTY_ID => 1,
71
            SystemProperties::PROPERTY_TYPE => Article::TYPE,
72
            SystemProperties::PROPERTY_REVISION => 1,
73
            SystemProperties::PROPERTY_CREATED => $now,
74
            SystemProperties::PROPERTY_MODIFIED => $now,
75
            SystemProperties::PROPERTY_LANGUAGE => getenv('OBJECT_DEFAULT_LANGUAGE'),
76
77
        ];
78
        /** @var ObjectInterface $object */
79
        $object = $this->getMockBuilder(AbstractObject::class)->disableOriginalConstructor()->getMock();
80
        $systemProperties = new SystemProperties($data, $object);
81
        $this->assertInstanceOf(SystemProperties::class, $systemProperties);
82
        $systemProperties = $systemProperties->publish();
83
        $systemProperties->publish();
84
    }
85
86
    /**
87
     * Test the instantiation of invalid system properties
88
     *
89
     * @expectedException \Apparat\Object\Domain\Model\Properties\InvalidArgumentException
90
     * @expectedExceptionCode 1456522289
91
     */
92
    public function testInvalidSystemProperties()
93
    {
94
        /** @var ObjectInterface $object */
95
        $object = $this->getMockBuilder(AbstractObject::class)->disableOriginalConstructor()->getMock();
96
        new SystemProperties([], $object);
97
    }
98
99
    /**
100
     * Test setting the object location
101
     *
102
     * @expectedException \Apparat\Object\Domain\Model\Properties\InvalidArgumentException
103
     * @expectedExceptionCode 1462903252
104
     */
105
    public function testObjectSetLocation()
106
    {
107
        $latitude = rand(0, 10000) / 10000;
108
        $longitude = rand(0, 10000) / 10000;
109
        $elevation = rand(0, 10000);
110
        $article = Object::load(getenv('REPOSITORY_URL').self::OBJECT_LOCATOR);
111
        $this->assertInstanceOf(Article::class, $article);
112
        $this->assertEquals($latitude, $article->setLatitude($latitude)->getLatitude());
113
114
        // Repeat the assignment to test unchanged returns
115
        $this->assertEquals($latitude, $article->setLatitude($latitude)->getLatitude());
116
117
        $this->assertEquals($longitude, $article->setLongitude($longitude)->getLongitude());
118
        $this->assertEquals($elevation, $article->setElevation($elevation)->getElevation());
119
        $article->setLatitude('invalid');
120
    }
121
}
122