ObjectAssertTrait::deepPropertyVal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace Peridot\Leo\Interfaces\Assert;
4
5
/**
6
 * ObjectAssertTrait contains assertions that deal
7
 * primarily with objects.
8
 *
9
 * @package Peridot\Leo\Interfaces\Assert
10
 */
11
trait ObjectAssertTrait
12
{
13
    /**
14
     * Perform an instanceof assertion.
15
     *
16
     * @param object $object
17
     * @param string $class
18
     * @param string $message
19
     */
20
    public function isInstanceOf($object, $class, $message = '')
21
    {
22
        $this->assertion->setActual($object);
0 ignored issues
show
Bug introduced by
The property assertion does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
24
        return $this->assertion->is->instanceof($class, $message);
25
    }
26
27
    /**
28
     * Perform a negated instanceof assertion.
29
     *
30
     * @param object $object
31
     * @param string $class
32
     * @param string $message
33
     */
34
    public function notInstanceOf($object, $class, $message = '')
35
    {
36
        $this->assertion->setActual($object);
37
38
        return $this->assertion->is->not->instanceof($class, $message);
39
    }
40
41
    /**
42
     * Perform a property assertion.
43
     *
44
     * @param array|object $object
45
     * @param string       $property
46
     * @param string       $message
47
     */
48
    public function property($object, $property, $message = '')
49
    {
50
        $this->assertion->setActual($object);
51
52
        return $this->assertion->to->have->property($property, null, $message);
53
    }
54
55
    /**
56
     * Perform a negated property assertion.
57
     *
58
     * @param array|object $object
59
     * @param string       $property
60
     * @param string       $message
61
     */
62
    public function notProperty($object, $property, $message = '')
63
    {
64
        $this->assertion->setActual($object);
65
66
        return $this->assertion->to->not->have->property($property, null, $message);
67
    }
68
69
    /**
70
     * Perform a deep property assertion.
71
     *
72
     * @param array|object $object
73
     * @param string       $property
74
     * @param string       $message
75
     */
76
    public function deepProperty($object, $property, $message = '')
77
    {
78
        $this->assertion->setActual($object);
79
80
        return $this->assertion->to->have->deep->property($property, null, $message);
81
    }
82
83
    /**
84
     * Perform a negated deep property assertion.
85
     *
86
     * @param array|object $object
87
     * @param string       $property
88
     * @param string       $message
89
     */
90
    public function notDeepProperty($object, $property, $message = '')
91
    {
92
        $this->assertion->setActual($object);
93
94
        return $this->assertion->to->not->have->deep->property($property, null, $message);
95
    }
96
97
    /**
98
     * Perform a property value assertion.
99
     *
100
     * @param array|object $object
101
     * @param string       $property
102
     * @param mixed        $value
103
     * @param string       $message
104
     */
105
    public function propertyVal($object, $property, $value, $message = '')
106
    {
107
        $this->assertion->setActual($object);
108
109
        return $this->assertion->to->have->property($property, $value, $message);
110
    }
111
112
    /**
113
     * Perform a negated property value assertion.
114
     *
115
     * @param array|object $object
116
     * @param string       $property
117
     * @param mixed        $value
118
     * @param string       $message
119
     */
120
    public function propertyNotVal($object, $property, $value, $message = '')
121
    {
122
        $this->assertion->setActual($object);
123
124
        return $this->assertion->to->not->have->property($property, $value, $message);
125
    }
126
127
    /**
128
     * Perform a deep property value assertion.
129
     *
130
     * @param array|object $object
131
     * @param string       $property
132
     * @param mixed        $value
133
     * @param string       $message
134
     */
135
    public function deepPropertyVal($object, $property, $value, $message = '')
136
    {
137
        $this->assertion->setActual($object);
138
139
        return $this->assertion->to->have->deep->property($property, $value, $message);
140
    }
141
142
    /**
143
     * Perform a negated deep property value assertion.
144
     *
145
     * @param array|object $object
146
     * @param string       $property
147
     * @param mixed        $value
148
     * @param string       $message
149
     */
150
    public function deepPropertyNotVal($object, $property, $value, $message = '')
151
    {
152
        $this->assertion->setActual($object);
153
154
        return $this->assertion->to->not->have->deep->property($property, $value, $message);
155
    }
156
}
157