Completed
Push — master ( bd6d37...98df61 )
by Joschi
03:30
created

PropertyModelTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 5 1
A testWithEmptyDatatypes() 0 4 1
A testWithInvalidDatatype() 0 4 1
A testFilteringWithDatatypeException() 0 10 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\Kernel\Ports\Kernel;
40
use Apparat\Object\Application\Model\Properties\Datatype\ApparatUrl;
41
use Apparat\Object\Application\Model\Properties\Domain\PropertyModel;
42
use Apparat\Object\Domain\Model\Object\ObjectInterface;
43
use Apparat\Object\Ports\Object;
44
45
/**
46
 * Property model tests
47
 *
48
 * @package Apparat\Object
49
 * @subpackage Apparat\Object\Tests
50
 */
51
class PropertyModelTest extends AbstractRepositoryEnabledTest
52
{
53
    /**
54
     * Object
55
     *
56
     * @var ObjectInterface
57
     */
58
    protected static $object;
59
    /**
60
     * Example object path
61
     *
62
     * @var string
63
     */
64
    const ARTICLE_PATH = '/2015/12/21/1-article/1';
65
    /**
66
     * Example Url
67
     *
68
     * @var string
69
     */
70
    const URL = 'http://example.com/path/to/resource?var=val';
71
72
    /**
73
     * Setup
74
     */
75
    public static function setUpBeforeClass()
76
    {
77
        parent::setUpBeforeClass();
78
        self::$object = Object::instance(getenv('REPOSITORY_URL').self::ARTICLE_PATH);
79
    }
80
81
    /**
82
     * Test a property model with empty datatypes
83
     *
84
     * @expectedException \Apparat\Object\Application\Model\Properties\Domain\InvalidArgumentException
85
     * @expectedExceptionCode 1465140832
86
     */
87
    public function testWithEmptyDatatypes()
88
    {
89
        Kernel::create(PropertyModel::class, [self::$object, false, []]);
90
    }
91
92
    /**
93
     * Test a property model with an invalid datatype
94
     *
95
     * @expectedException \Apparat\Object\Application\Model\Properties\Domain\InvalidArgumentException
96
     * @expectedExceptionCode 1465141877
97
     */
98
    public function testWithInvalidDatatype()
99
    {
100
        Kernel::create(PropertyModel::class, [self::$object, false, [PropertyModel::class]]);
101
    }
102
103
    /**
104
     * Test filtering with a datatype exception
105
     *
106
     * @expectedException \Apparat\Object\Application\Model\Properties\Domain\DomainException
107
     * @expectedExceptionCode 1465140806
108
     */
109
    public function testFilteringWithDatatypeException()
110
    {
111
        /** @var PropertyModel $propertyModel */
112
        $propertyModel = Kernel::create(
113
            PropertyModel::class,
114
            [self::$object, false, [ApparatUrl::class], [ApparatUrl::class => Object::CONTACT]]
115
        );
116
        $this->assertNull($propertyModel->filterValue(''));
117
        $propertyModel->filterValue(self::ARTICLE_PATH);
118
    }
119
}
120