1 | <?php |
||
15 | class PropertyMatcher extends AbstractMatcher |
||
16 | { |
||
17 | /** |
||
18 | * @var string|int |
||
19 | */ |
||
20 | protected $key; |
||
21 | |||
22 | /** |
||
23 | * @var mixed |
||
24 | */ |
||
25 | protected $value; |
||
26 | |||
27 | /** |
||
28 | * @var mixed |
||
29 | */ |
||
30 | protected $actualValue; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | protected $actualValueSet = false; |
||
36 | |||
37 | /** |
||
38 | * @var bool |
||
39 | */ |
||
40 | protected $isDeep = false; |
||
41 | |||
42 | /** |
||
43 | * @param mixed $key |
||
44 | * @param string $value |
||
45 | */ |
||
46 | public function __construct($key, $value = "") |
||
52 | |||
53 | /** |
||
54 | * Return the expected object or array key. |
||
55 | * |
||
56 | * @return int|string |
||
57 | */ |
||
58 | public function getKey() |
||
62 | |||
63 | /** |
||
64 | * Set the expected object or array key. |
||
65 | * |
||
66 | * @param int|string $key |
||
67 | * @return $this |
||
68 | */ |
||
69 | public function setKey($key) |
||
74 | |||
75 | /** |
||
76 | * Return the expected property value. |
||
77 | * |
||
78 | * @return mixed |
||
79 | */ |
||
80 | public function getValue() |
||
84 | |||
85 | /** |
||
86 | * Set the expected property value. |
||
87 | * |
||
88 | * @param mixed $value |
||
89 | * @return $this |
||
90 | */ |
||
91 | public function setValue($value) |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | * |
||
100 | * @return TemplateInterface |
||
101 | */ |
||
102 | public function getDefaultTemplate() |
||
117 | |||
118 | /** |
||
119 | * Return the actual value given to the matcher. |
||
120 | * |
||
121 | * @return mixed |
||
122 | */ |
||
123 | public function getActualValue() |
||
127 | |||
128 | /** |
||
129 | * Set the actual value given to the matcher. Used to |
||
130 | * store whether or not the actual value was set. |
||
131 | * |
||
132 | * @param mixed $actualValue |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function setActualValue($actualValue) |
||
141 | |||
142 | /** |
||
143 | * Return if the actual value has been set. |
||
144 | * |
||
145 | * @return bool |
||
146 | */ |
||
147 | public function isActualValueSet() |
||
151 | |||
152 | /** |
||
153 | * Tell the property matcher to match deep properties. |
||
154 | * |
||
155 | * return $this |
||
156 | */ |
||
157 | public function setIsDeep($isDeep) |
||
162 | |||
163 | /** |
||
164 | * Return whether or not the matcher is matching deep properties. |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | public function isDeep() |
||
172 | |||
173 | /** |
||
174 | * Matches if the actual value has a property, optionally matching |
||
175 | * the expected value of that property. If the deep flag is set, |
||
176 | * the matcher will use the ObjectPath utility to parse deep expressions. |
||
177 | * |
||
178 | * @code |
||
179 | * |
||
180 | * $this->doMatch('child->name->first', 'brian'); |
||
181 | * |
||
182 | * @endcode |
||
183 | * |
||
184 | * @param mixed $actual |
||
185 | * @return mixed |
||
186 | */ |
||
187 | protected function doMatch($actual) |
||
199 | |||
200 | /** |
||
201 | * Convert the actual value to an array, whether it is an object or an array. |
||
202 | * |
||
203 | * @param object|array $actual |
||
204 | * @return array|object |
||
205 | */ |
||
206 | protected function actualToArray($actual) |
||
213 | |||
214 | /** |
||
215 | * Match that an array index exists, and matches |
||
216 | * the expected value if set. |
||
217 | * |
||
218 | * @param $actual |
||
219 | * @return bool |
||
220 | */ |
||
221 | protected function matchArrayIndex($actual) |
||
230 | |||
231 | /** |
||
232 | * Uses ObjectPath to parse an expression if the deep flag |
||
233 | * is set. |
||
234 | * |
||
235 | * @param $actual |
||
236 | * @return bool |
||
237 | */ |
||
238 | protected function matchDeep($actual) |
||
251 | |||
252 | /** |
||
253 | * Check if the given value is expected. |
||
254 | * |
||
255 | * @param $value |
||
256 | * @return bool |
||
257 | */ |
||
258 | protected function isExpected($value) |
||
267 | |||
268 | /** |
||
269 | * Ensure that the actual value is an object or an array. |
||
270 | * |
||
271 | * @param $actual |
||
272 | */ |
||
273 | protected function validateActual($actual) |
||
279 | |||
280 | /** |
||
281 | * Returns the strings used in creating the template for the matcher. |
||
282 | * |
||
283 | * @return array |
||
284 | */ |
||
285 | protected function getTemplateStrings() |
||
302 | } |
||
303 |