@@ -29,6 +29,20 @@ protected function setUp()
29
29
$ this ->propertyAccessor = new PropertyAccessor ();
30
30
}
31
31
32
+ public function getPathsWithUnexpectedType ()
33
+ {
34
+ return array (
35
+ array ('' , 'foobar ' ),
36
+ array ('foo ' , 'foobar ' ),
37
+ array (null , 'foobar ' ),
38
+ array (123 , 'foobar ' ),
39
+ array ((object ) array ('prop ' => null ), 'prop.foobar ' ),
40
+ array ((object ) array ('prop ' => (object ) array ('subProp ' => null )), 'prop.subProp.foobar ' ),
41
+ array (array ('index ' => null ), '[index][foobar] ' ),
42
+ array (array ('index ' => array ('subIndex ' => null )), '[index][subIndex][foobar] ' ),
43
+ );
44
+ }
45
+
32
46
public function testGetValueReadsArray ()
33
47
{
34
48
$ array = array ('firstName ' => 'Bernhard ' );
@@ -198,27 +212,13 @@ public function testGetValueThrowsExceptionIfPropertyDoesNotExist()
198
212
}
199
213
200
214
/**
215
+ * @dataProvider getPathsWithUnexpectedType
201
216
* @expectedException \Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException
217
+ * @expectedExceptionMessage Expected argument of type "object or array"
202
218
*/
203
- public function testGetValueThrowsExceptionIfNotObjectOrArray ()
204
- {
205
- $ this ->propertyAccessor ->getValue ('baz ' , 'foobar ' );
206
- }
207
-
208
- /**
209
- * @expectedException \Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException
210
- */
211
- public function testGetValueThrowsExceptionIfNull ()
219
+ public function testGetValueThrowsExceptionIfNotObjectOrArray ($ objectOrArray , $ path )
212
220
{
213
- $ this ->propertyAccessor ->getValue (null , 'foobar ' );
214
- }
215
-
216
- /**
217
- * @expectedException \Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException
218
- */
219
- public function testGetValueThrowsExceptionIfEmpty ()
220
- {
221
- $ this ->propertyAccessor ->getValue ('' , 'foobar ' );
221
+ $ this ->propertyAccessor ->getValue ($ objectOrArray , $ path );
222
222
}
223
223
224
224
public function testGetValueWhenArrayValueIsNull ()
@@ -311,33 +311,13 @@ public function testSetValueThrowsExceptionIfGetterIsNotPublic()
311
311
}
312
312
313
313
/**
314
+ * @dataProvider getPathsWithUnexpectedType
314
315
* @expectedException \Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException
316
+ * @expectedExceptionMessage Expected argument of type "object or array"
315
317
*/
316
- public function testSetValueThrowsExceptionIfNotObjectOrArray ()
318
+ public function testSetValueThrowsExceptionIfNotObjectOrArray ($ objectOrArray , $ path )
317
319
{
318
- $ value = 'baz ' ;
319
-
320
- $ this ->propertyAccessor ->setValue ($ value , 'foobar ' , 'bam ' );
321
- }
322
-
323
- /**
324
- * @expectedException \Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException
325
- */
326
- public function testSetValueThrowsExceptionIfNull ()
327
- {
328
- $ value = null ;
329
-
330
- $ this ->propertyAccessor ->setValue ($ value , 'foobar ' , 'bam ' );
331
- }
332
-
333
- /**
334
- * @expectedException \Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException
335
- */
336
- public function testSetValueThrowsExceptionIfEmpty ()
337
- {
338
- $ value = '' ;
339
-
340
- $ this ->propertyAccessor ->setValue ($ value , 'foobar ' , 'bam ' );
320
+ $ this ->propertyAccessor ->setValue ($ objectOrArray , $ path , 'value ' );
341
321
}
342
322
343
323
/**
0 commit comments