1 | <?php |
||
10 | trait ObjectAssertTrait |
||
11 | { |
||
12 | /** |
||
13 | * Perform an instanceof assertion. |
||
14 | * |
||
15 | * @param object $object |
||
16 | * @param string $class |
||
17 | * @param string $message |
||
18 | */ |
||
19 | public function isInstanceOf($object, $class, $message = "") |
||
24 | |||
25 | /** |
||
26 | * Perform a negated instanceof assertion. |
||
27 | * |
||
28 | * @param object $object |
||
29 | * @param string $class |
||
30 | * @param string $message |
||
31 | */ |
||
32 | public function notInstanceOf($object, $class, $message = "") |
||
37 | |||
38 | /** |
||
39 | * Perform a property assertion. |
||
40 | * |
||
41 | * @param array|object $actual |
||
42 | * @param string $property |
||
43 | * @param string $message |
||
44 | */ |
||
45 | public function property($object, $property, $message = "") |
||
50 | |||
51 | /** |
||
52 | * Perform a negated property assertion. |
||
53 | * |
||
54 | * @param array|object $actual |
||
55 | * @param string $property |
||
56 | * @param string $message |
||
57 | */ |
||
58 | public function notProperty($object, $property, $message = "") |
||
63 | |||
64 | /** |
||
65 | * Perform a deep property assertion. |
||
66 | * |
||
67 | * @param array|object $object |
||
68 | * @param string $property |
||
69 | * @param string $message |
||
70 | */ |
||
71 | public function deepProperty($object, $property, $message = "") |
||
76 | |||
77 | /** |
||
78 | * Perform a negated deep property assertion. |
||
79 | * |
||
80 | * @param array|object $actual |
||
81 | * @param string $property |
||
82 | * @param string $message |
||
83 | */ |
||
84 | public function notDeepProperty($object, $property, $message = "") |
||
89 | |||
90 | /** |
||
91 | * Perform a property value assertion. |
||
92 | * |
||
93 | * @param array|object $object |
||
94 | * @param string $property |
||
95 | * @param mixed $value |
||
96 | * @param string $message |
||
97 | */ |
||
98 | public function propertyVal($object, $property, $value, $message = "") |
||
103 | |||
104 | /** |
||
105 | * Perform a negated property value assertion. |
||
106 | * |
||
107 | * @param array|object $object |
||
108 | * @param string $property |
||
109 | * @param mixed $value |
||
110 | * @param string $message |
||
111 | */ |
||
112 | public function propertyNotVal($object, $property, $value, $message = "") |
||
117 | |||
118 | /** |
||
119 | * Perform a deep property value assertion. |
||
120 | * |
||
121 | * @param array|object $object |
||
122 | * @param string $property |
||
123 | * @param mixed $value |
||
124 | * @param string $message |
||
125 | */ |
||
126 | public function deepPropertyVal($object, $property, $value, $message = "") |
||
131 | |||
132 | /** |
||
133 | * Perform a negated deep property value assertion. |
||
134 | * |
||
135 | * @param array|object $object |
||
136 | * @param string $property |
||
137 | * @param mixed $value |
||
138 | * @param string $message |
||
139 | */ |
||
140 | public function deepPropertyNotVal($object, $property, $value, $message = "") |
||
145 | } |
||
146 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: