48
48
* * 'value_callback': callable || method name (in the TestCase class)
49
49
* The return value of that callback is taken as value for the test.
50
50
*
51
- * * 'property': If there is no getter method, you may want to test, wether the setter has set
52
- * a property on the SUT properly. This key may be
53
- * - true: The name equals the property to check
54
- * - string: Name of property to hold the expected value
55
- * - [{PropertyName, }expected value (if differs from 'value']
56
- *
57
- * * 'property_assert': callback for property assertion.
58
- * see 'assert'. But please note:
59
- * strings are 'converted' to 'assertAttribute*' methods.
60
- * The callback gets passed the expected value, the name of the
61
- * property ('property') and the SUT instance.
62
- * DEFAULT: 'equals' ( => static::assertAttributeEquals)
63
- *
64
51
* * 'getter': - Name of getter method (a '*' gets replaced by the property name)
65
52
* - [GetterName, [arg, arg, ...]]
66
53
* Use this format to provide arguments to the getter method.
@@ -167,17 +154,7 @@ public function testSetterAndGetter($name, $spec = null): void
167
154
}
168
155
}
169
156
170
- // Test property
171
- if (null !== $ spec ['property ' ]) {
172
- [$ propertyName , $ propertyValue ] = $ spec ['property ' ];
173
- if ('__VALUE__ ' == $ propertyValue ) {
174
- $ propertyValue = $ value ;
175
- }
176
-
177
- $ spec ['property_assert ' ]($ propertyValue , $ propertyName , $ target );
178
-
179
- // Test getter
180
- } elseif (false !== $ spec ['getter ' ][0 ]) {
157
+ if (false !== $ spec ['getter ' ][0 ]) {
181
158
$ getter = str_replace ('* ' , $ name , $ spec ['getter ' ][0 ]);
182
159
$ getterValue = $ target ->$ getter (...$ spec ['getter ' ][1 ]);
183
160
$ spec ['assert ' ]($ value , $ getterValue );
@@ -196,8 +173,6 @@ public function testSetterAndGetter($name, $spec = null): void
196
173
private function setterAndGetterNormalizeSpec ($ spec , string $ name , object $ target ): array
197
174
{
198
175
$ normalized = [
199
- 'property ' => null ,
200
- 'property_assert ' => [static ::class, 'assertAttributeEquals ' ],
201
176
'getter ' => ["get* " , []],
202
177
'assert ' => [static ::class, 'assertEquals ' ],
203
178
'setter ' => ["set* " , []],
@@ -215,31 +190,14 @@ private function setterAndGetterNormalizeSpec($spec, string $name, object $targe
215
190
$ err = __TRAIT__ . ': ' . get_class ($ this ) . ': ' ;
216
191
217
192
if (!is_array ($ spec )) {
218
- throw new \PHPUnit_Framework_Exception ($ err . 'Invalid specification. Must be array. ' );
193
+ throw new \PHPUnit \ Framework \ Exception ($ err . 'Invalid specification. Must be array. ' );
219
194
}
220
195
221
196
foreach ($ spec as $ key => $ value ) {
222
197
switch ($ key ) {
223
198
default :
224
199
break ;
225
200
226
- case 'property ' :
227
- if (true === $ value ) {
228
- $ value = [$ name , '__VALUE__ ' ];
229
- break ;
230
- }
231
-
232
- if (is_array ($ value )) {
233
- $ value = isset ($ value [1 ])
234
- ? [true === $ value [0 ] ? $ name : $ value [0 ], $ value [1 ]]
235
- : [$ name , $ value [0 ]]
236
- ;
237
- break ;
238
- }
239
-
240
- $ value = [$ value , '__VALUE__ ' ];
241
- break ;
242
-
243
201
case 'setter_value ' :
244
202
if ('__SELF__ ' == $ value ) {
245
203
$ value = $ target ;
@@ -286,7 +244,7 @@ private function setterAndGetterNormalizeSpec($spec, string $name, object $targe
286
244
}
287
245
288
246
if (!is_callable ($ value )) {
289
- throw new \PHPUnit_Framework_Exception ($ err . 'Invalid value callback. ' );
247
+ throw new \PHPUnit \ Framework \ Exception ($ err . 'Invalid value callback. ' );
290
248
}
291
249
292
250
$ key = substr ($ key , 0 , -9 );
@@ -295,19 +253,17 @@ private function setterAndGetterNormalizeSpec($spec, string $name, object $targe
295
253
296
254
case 'setter_assert ' :
297
255
case 'assert ' :
298
- case 'property_assert ' :
299
256
if (is_string ($ value )) {
300
257
if (method_exists ($ this , $ value )) {
301
258
$ value = [$ this , $ value ];
302
259
break ;
303
260
}
304
- $ attr = 'property_assert ' == $ key ? 'Attribute ' : '' ;
305
- $ value = [static ::class, "assert $ attr$ value " ];
261
+ $ value = [static ::class, "assert $ value " ];
306
262
break ;
307
263
}
308
264
309
265
if (!is_callable ($ value )) {
310
- throw new \PHPUnit_Framework_Exception ($ err . 'Invalid assert callback. ' );
266
+ throw new \PHPUnit \ Framework \ Exception ($ err . 'Invalid assert callback. ' );
311
267
}
312
268
313
269
break ;
0 commit comments