Completed
Push — master ( 3bf76e...9f9c26 )
by Joschi
04:22
created

SystemPropertiesTest::testObjectAddRelation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 11
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 16
rs 9.4285
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\Ports\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 path
55
     *
56
     * @var string
57
     */
58
    const OBJECT_PATH = '/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
        $data = [
69
            'id' => 1,
70
            'type' => 'article',
71
            'revision' => 1,
72
            'created' => time(),
73
            'hash' => sha1(rand()),
74
        ];
75
        /** @var ObjectInterface $object */
76
        $object = $this->getMockBuilder(AbstractObject::class)->disableOriginalConstructor()->getMock();
77
        $systemProperties = new SystemProperties($data, $object);
78
        $this->assertInstanceOf(SystemProperties::class, $systemProperties);
79
        $systemProperties = $systemProperties->publish();
80
        $systemProperties->publish();
81
    }
82
83
    /**
84
     * Test the instantiation of invalid system properties
85
     *
86
     * @expectedException \Apparat\Object\Domain\Model\Properties\InvalidArgumentException
87
     * @expectedExceptionCode 1456522289
88
     */
89
    public function testInvalidSystemProperties()
90
    {
91
        /** @var ObjectInterface $object */
92
        $object = $this->getMockBuilder(AbstractObject::class)->disableOriginalConstructor()->getMock();
93
        new SystemProperties([], $object);
94
    }
95
96
    /**
97
     * Test setting the object location
98
     *
99
     * @expectedException \Apparat\Object\Domain\Model\Properties\InvalidArgumentException
100
     * @expectedExceptionCode 1462903252
101
     */
102
    public function testObjectSetLocation()
103
    {
104
        $latitude = rand(0, 10000) / 10000;
105
        $longitude = rand(0, 10000) / 10000;
106
        $elevation = rand(0, 10000);
107
        $article = Object::instance(getenv('REPOSITORY_URL').self::OBJECT_PATH);
108
        $this->assertInstanceOf(Article::class, $article);
109
        $this->assertEquals($latitude, $article->setLatitude($latitude)->getLatitude());
110
111
        // Repeat the assignment to test unchanged returns
112
        $this->assertEquals($latitude, $article->setLatitude($latitude)->getLatitude());
113
114
        $this->assertEquals($longitude, $article->setLongitude($longitude)->getLongitude());
115
        $this->assertEquals($elevation, $article->setElevation($elevation)->getElevation());
116
        $article->setLatitude('invalid');
117
    }
118
}
119