@@ -21,25 +21,28 @@ public function testGetValueReadsArray()
21
21
{
22
22
$ array = array ('firstName ' => 'Bernhard ' );
23
23
24
- $ path = new PropertyPath ('firstName ' );
24
+ $ path = new PropertyPath ('[ firstName] ' );
25
25
26
26
$ this ->assertEquals ('Bernhard ' , $ path ->getValue ($ array ));
27
27
}
28
28
29
- public function testGetValueIgnoresSingular ()
29
+ /**
30
+ * @expectedException Symfony\Component\Form\Exception\InvalidPropertyException
31
+ */
32
+ public function testGetValueThrowsExceptionIfIndexNotationExpected ()
30
33
{
31
- $ array = array ('children ' => 'Many ' );
34
+ $ array = array ('firstName ' => 'Bernhard ' );
32
35
33
- $ path = new PropertyPath ('children|child ' );
36
+ $ path = new PropertyPath ('firstName ' );
34
37
35
- $ this -> assertEquals ( ' Many ' , $ path ->getValue ($ array) );
38
+ $ path ->getValue ($ array );
36
39
}
37
40
38
41
public function testGetValueReadsZeroIndex ()
39
42
{
40
43
$ array = array ('Bernhard ' );
41
44
42
- $ path = new PropertyPath ('0 ' );
45
+ $ path = new PropertyPath ('[0] ' );
43
46
44
47
$ this ->assertEquals ('Bernhard ' , $ path ->getValue ($ array ));
45
48
}
@@ -53,20 +56,11 @@ public function testGetValueReadsIndexWithSpecialChars()
53
56
$ this ->assertEquals ('Bernhard ' , $ path ->getValue ($ array ));
54
57
}
55
58
56
- public function testGetValueReadsElementWithSpecialCharsExceptDot ()
57
- {
58
- $ array = array ('%!@$§ ' => 'Bernhard ' );
59
-
60
- $ path = new PropertyPath ('%!@$§ ' );
61
-
62
- $ this ->assertEquals ('Bernhard ' , $ path ->getValue ($ array ));
63
- }
64
-
65
59
public function testGetValueReadsNestedIndexWithSpecialChars ()
66
60
{
67
61
$ array = array ('root ' => array ('%!@$§. ' => 'Bernhard ' ));
68
62
69
- $ path = new PropertyPath ('root[%!@$§.] ' );
63
+ $ path = new PropertyPath ('[ root] [%!@$§.] ' );
70
64
71
65
$ this ->assertEquals ('Bernhard ' , $ path ->getValue ($ array ));
72
66
}
@@ -75,7 +69,7 @@ public function testGetValueReadsArrayWithCustomPropertyPath()
75
69
{
76
70
$ array = array ('child ' => array ('index ' => array ('firstName ' => 'Bernhard ' )));
77
71
78
- $ path = new PropertyPath ('child[index]. firstName ' );
72
+ $ path = new PropertyPath ('[ child] [index][ firstName] ' );
79
73
80
74
$ this ->assertEquals ('Bernhard ' , $ path ->getValue ($ array ));
81
75
}
@@ -84,7 +78,7 @@ public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath()
84
78
{
85
79
$ array = array ('child ' => array ('index ' => array ()));
86
80
87
- $ path = new PropertyPath ('child[index]. firstName ' );
81
+ $ path = new PropertyPath ('[ child] [index][ firstName] ' );
88
82
89
83
$ this ->assertNull ($ path ->getValue ($ array ));
90
84
}
@@ -99,6 +93,24 @@ public function testGetValueReadsProperty()
99
93
$ this ->assertEquals ('Bernhard ' , $ path ->getValue ($ object ));
100
94
}
101
95
96
+ public function testGetValueIgnoresSingular ()
97
+ {
98
+ $ object = (object ) array ('children ' => 'Many ' );
99
+
100
+ $ path = new PropertyPath ('children|child ' );
101
+
102
+ $ this ->assertEquals ('Many ' , $ path ->getValue ($ object ));
103
+ }
104
+
105
+ public function testGetValueReadsPropertyWithSpecialCharsExceptDot ()
106
+ {
107
+ $ array = (object ) array ('%!@$§ ' => 'Bernhard ' );
108
+
109
+ $ path = new PropertyPath ('%!@$§ ' );
110
+
111
+ $ this ->assertEquals ('Bernhard ' , $ path ->getValue ($ array ));
112
+ }
113
+
102
114
public function testGetValueReadsPropertyWithCustomPropertyPath ()
103
115
{
104
116
$ object = new Author ();
@@ -121,21 +133,23 @@ public function testGetValueReadsArrayAccess()
121
133
$ this ->assertEquals ('Bernhard ' , $ path ->getValue ($ object ));
122
134
}
123
135
136
+ /**
137
+ * @expectedException Symfony\Component\Form\Exception\InvalidPropertyException
138
+ */
124
139
public function testGetValueThrowsExceptionIfArrayAccessExpected ()
125
140
{
126
141
$ path = new PropertyPath ('[firstName] ' );
127
142
128
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\InvalidPropertyException ' );
129
-
130
143
$ path ->getValue (new Author ());
131
144
}
132
145
146
+ /**
147
+ * @expectedException Symfony\Component\Form\Exception\PropertyAccessDeniedException
148
+ */
133
149
public function testGetValueThrowsExceptionIfPropertyIsNotPublic ()
134
150
{
135
151
$ path = new PropertyPath ('privateProperty ' );
136
152
137
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\PropertyAccessDeniedException ' );
138
-
139
153
$ path ->getValue (new Author ());
140
154
}
141
155
@@ -159,12 +173,13 @@ public function testGetValueCamelizesGetterNames()
159
173
$ this ->assertEquals ('Schussek ' , $ path ->getValue ($ object ));
160
174
}
161
175
176
+ /**
177
+ * @expectedException Symfony\Component\Form\Exception\PropertyAccessDeniedException
178
+ */
162
179
public function testGetValueThrowsExceptionIfGetterIsNotPublic ()
163
180
{
164
181
$ path = new PropertyPath ('privateGetter ' );
165
182
166
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\PropertyAccessDeniedException ' );
167
-
168
183
$ path ->getValue (new Author ());
169
184
}
170
185
@@ -198,66 +213,82 @@ public function testGetValueReadsMagicGet()
198
213
$ this ->assertSame ('foobar ' , $ path ->getValue ($ object ));
199
214
}
200
215
216
+ /**
217
+ * @expectedException Symfony\Component\Form\Exception\PropertyAccessDeniedException
218
+ */
201
219
public function testGetValueThrowsExceptionIfIsserIsNotPublic ()
202
220
{
203
221
$ path = new PropertyPath ('privateIsser ' );
204
222
205
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\PropertyAccessDeniedException ' );
206
-
207
223
$ path ->getValue (new Author ());
208
224
}
209
225
226
+ /**
227
+ * @expectedException Symfony\Component\Form\Exception\InvalidPropertyException
228
+ */
210
229
public function testGetValueThrowsExceptionIfPropertyDoesNotExist ()
211
230
{
212
231
$ path = new PropertyPath ('foobar ' );
213
232
214
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\InvalidPropertyException ' );
215
-
216
233
$ path ->getValue (new Author ());
217
234
}
218
235
236
+ /**
237
+ * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
238
+ */
219
239
public function testGetValueThrowsExceptionIfNotObjectOrArray ()
220
240
{
221
241
$ path = new PropertyPath ('foobar ' );
222
242
223
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\UnexpectedTypeException ' );
224
-
225
243
$ path ->getValue ('baz ' );
226
244
}
227
245
246
+ /**
247
+ * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
248
+ */
228
249
public function testGetValueThrowsExceptionIfNull ()
229
250
{
230
251
$ path = new PropertyPath ('foobar ' );
231
252
232
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\UnexpectedTypeException ' );
233
-
234
253
$ path ->getValue (null );
235
254
}
236
255
256
+ /**
257
+ * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
258
+ */
237
259
public function testGetValueThrowsExceptionIfEmpty ()
238
260
{
239
261
$ path = new PropertyPath ('foobar ' );
240
262
241
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\UnexpectedTypeException ' );
242
-
243
263
$ path ->getValue ('' );
244
264
}
245
265
246
266
public function testSetValueUpdatesArrays ()
247
267
{
248
268
$ array = array ();
249
269
250
- $ path = new PropertyPath ('firstName ' );
270
+ $ path = new PropertyPath ('[ firstName] ' );
251
271
$ path ->setValue ($ array , 'Bernhard ' );
252
272
253
273
$ this ->assertEquals (array ('firstName ' => 'Bernhard ' ), $ array );
254
274
}
255
275
276
+ /**
277
+ * @expectedException Symfony\Component\Form\Exception\InvalidPropertyException
278
+ */
279
+ public function testSetValueThrowsExceptionIfIndexNotationExpected ()
280
+ {
281
+ $ array = array ();
282
+
283
+ $ path = new PropertyPath ('firstName ' );
284
+ $ path ->setValue ($ array , 'Bernhard ' );
285
+ }
286
+
256
287
public function testSetValueUpdatesArraysWithCustomPropertyPath ()
257
288
{
258
289
$ array = array ();
259
290
260
- $ path = new PropertyPath ('child[index]. firstName ' );
291
+ $ path = new PropertyPath ('[ child] [index][ firstName] ' );
261
292
$ path ->setValue ($ array , 'Bernhard ' );
262
293
263
294
$ this ->assertEquals (array ('child ' => array ('index ' => array ('firstName ' => 'Bernhard ' ))), $ array );
@@ -305,12 +336,13 @@ public function testSetValueUpdateMagicSet()
305
336
$ this ->assertEquals ('foobar ' , $ object ->__get ('magicProperty ' ));
306
337
}
307
338
339
+ /**
340
+ * @expectedException Symfony\Component\Form\Exception\InvalidPropertyException
341
+ */
308
342
public function testSetValueThrowsExceptionIfArrayAccessExpected ()
309
343
{
310
344
$ path = new PropertyPath ('[firstName] ' );
311
345
312
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\InvalidPropertyException ' );
313
-
314
346
$ path ->setValue (new Author (), 'Bernhard ' );
315
347
}
316
348
@@ -334,42 +366,46 @@ public function testSetValueCamelizesSetterNames()
334
366
$ this ->assertEquals ('Schussek ' , $ object ->getLastName ());
335
367
}
336
368
369
+ /**
370
+ * @expectedException Symfony\Component\Form\Exception\PropertyAccessDeniedException
371
+ */
337
372
public function testSetValueThrowsExceptionIfGetterIsNotPublic ()
338
373
{
339
374
$ path = new PropertyPath ('privateSetter ' );
340
375
341
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\PropertyAccessDeniedException ' );
342
-
343
376
$ path ->setValue (new Author (), 'foobar ' );
344
377
}
345
378
379
+ /**
380
+ * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
381
+ */
346
382
public function testSetValueThrowsExceptionIfNotObjectOrArray ()
347
383
{
348
384
$ path = new PropertyPath ('foobar ' );
349
385
$ value = 'baz ' ;
350
386
351
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\UnexpectedTypeException ' );
352
-
353
387
$ path ->setValue ($ value , 'bam ' );
354
388
}
355
389
390
+ /**
391
+ * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
392
+ */
356
393
public function testSetValueThrowsExceptionIfNull ()
357
394
{
358
395
$ path = new PropertyPath ('foobar ' );
359
396
$ value = null ;
360
397
361
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\UnexpectedTypeException ' );
362
-
363
398
$ path ->setValue ($ value , 'bam ' );
364
399
}
365
400
401
+ /**
402
+ * @expectedException Symfony\Component\Form\Exception\UnexpectedTypeException
403
+ */
366
404
public function testSetValueThrowsExceptionIfEmpty ()
367
405
{
368
406
$ path = new PropertyPath ('foobar ' );
369
407
$ value = '' ;
370
408
371
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\UnexpectedTypeException ' );
372
-
373
409
$ path ->setValue ($ value , 'bam ' );
374
410
}
375
411
@@ -380,31 +416,35 @@ public function testToString()
380
416
$ this ->assertEquals ('reference.traversable[index].property ' , $ path ->__toString ());
381
417
}
382
418
419
+ /**
420
+ * @expectedException Symfony\Component\Form\Exception\InvalidPropertyPathException
421
+ */
383
422
public function testInvalidPropertyPath_noDotBeforeProperty ()
384
423
{
385
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\InvalidPropertyPathException ' );
386
-
387
424
new PropertyPath ('[index]property ' );
388
425
}
389
426
427
+ /**
428
+ * @expectedException Symfony\Component\Form\Exception\InvalidPropertyPathException
429
+ */
390
430
public function testInvalidPropertyPath_dotAtTheBeginning ()
391
431
{
392
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\InvalidPropertyPathException ' );
393
-
394
432
new PropertyPath ('.property ' );
395
433
}
396
434
435
+ /**
436
+ * @expectedException Symfony\Component\Form\Exception\InvalidPropertyPathException
437
+ */
397
438
public function testInvalidPropertyPath_unexpectedCharacters ()
398
439
{
399
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\InvalidPropertyPathException ' );
400
-
401
440
new PropertyPath ('property.$form ' );
402
441
}
403
442
443
+ /**
444
+ * @expectedException Symfony\Component\Form\Exception\InvalidPropertyPathException
445
+ */
404
446
public function testInvalidPropertyPath_null ()
405
447
{
406
- $ this ->setExpectedException ('Symfony\Component\Form\Exception\InvalidPropertyPathException ' );
407
-
408
448
new PropertyPath (null );
409
449
}
410
450
0 commit comments