@@ -37,7 +37,7 @@ class FieldEvaluatorTest extends TestCase
3737 */
3838 private $ expressionLanguage ;
3939
40- protected function setUp ()
40+ protected function setUp (): void
4141 {
4242 parent ::setUp ();
4343 $ this ->expressionLanguage = $ this ->prophesize ('Symfony\Component\ExpressionLanguage\ExpressionLanguage ' );
@@ -225,4 +225,148 @@ public function testEvaluateConditionWithError()
225225
226226 $ this ->fieldEvaluator ->evaluateCondition (['test ' => true ], 'invalid_syntax ' );
227227 }
228+
229+ /**
230+ * Test getPropertyValue method specifically
231+ */
232+ public function testGetPropertyValueWithNullObject ()
233+ {
234+ $ field = new Property ('someProperty ' );
235+ $ result = $ this ->fieldEvaluator ->getValue (null , $ field );
236+
237+ $ this ->assertNull ($ result );
238+ }
239+
240+ public function testGetPropertyValueWithValidObject ()
241+ {
242+ $ product = new Product ();
243+ $ product ->title = 'Test Product ' ;
244+
245+ $ field = new Property ('title ' );
246+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
247+
248+ $ this ->assertSame ('Test Product ' , $ result );
249+ }
250+
251+ public function testGetPropertyValueWithArrayAccess ()
252+ {
253+ $ data = ['name ' => 'Test Name ' , 'value ' => 123 ];
254+
255+ $ field = new Property ('[name] ' );
256+ $ result = $ this ->fieldEvaluator ->getValue ($ data , $ field );
257+
258+ $ this ->assertSame ('Test Name ' , $ result );
259+ }
260+
261+ public function testGetPropertyValueWithNestedProperty ()
262+ {
263+ $ product = new Product ();
264+ $ category = new \stdClass ();
265+ $ category ->name = 'Electronics ' ;
266+ $ product ->category = $ category ;
267+
268+ $ field = new Property ('category.name ' );
269+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
270+
271+ $ this ->assertSame ('Electronics ' , $ result );
272+ }
273+
274+ public function testGetPropertyValueWithNullProperty ()
275+ {
276+ $ product = new Product ();
277+ $ product ->description = null ;
278+
279+ $ field = new Property ('description ' );
280+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
281+
282+ $ this ->assertNull ($ result );
283+ }
284+
285+ public function testGetPropertyValueWithBooleanProperty ()
286+ {
287+ $ product = new Product ();
288+ $ product ->isActive = false ;
289+
290+ $ field = new Property ('isActive ' );
291+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
292+
293+ $ this ->assertFalse ($ result );
294+ }
295+
296+ public function testGetPropertyValueWithIntegerProperty ()
297+ {
298+ $ product = new Product ();
299+ $ product ->quantity = 0 ;
300+
301+ $ field = new Property ('quantity ' );
302+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
303+
304+ $ this ->assertSame (0 , $ result );
305+ }
306+
307+ public function testGetPropertyValueWithFloatProperty ()
308+ {
309+ $ product = new Product ();
310+ $ product ->price = 19.99 ;
311+
312+ $ field = new Property ('price ' );
313+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
314+
315+ $ this ->assertSame (19.99 , $ result );
316+ }
317+
318+ public function testGetPropertyValueWithArrayProperty ()
319+ {
320+ $ product = new Product ();
321+ $ product ->tags = ['tag1 ' , 'tag2 ' , 'tag3 ' ];
322+
323+ $ field = new Property ('tags ' );
324+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
325+
326+ $ this ->assertSame (['tag1 ' , 'tag2 ' , 'tag3 ' ], $ result );
327+ }
328+
329+ public function testGetPropertyValueWithEmptyArrayProperty ()
330+ {
331+ $ product = new Product ();
332+ $ product ->tags = [];
333+
334+ $ field = new Property ('tags ' );
335+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
336+
337+ $ this ->assertSame ([], $ result );
338+ }
339+
340+ public function testGetPropertyValueWithEmptyStringProperty ()
341+ {
342+ $ product = new Product ();
343+ $ product ->title = '' ;
344+
345+ $ field = new Property ('title ' );
346+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
347+
348+ $ this ->assertSame ('' , $ result );
349+ }
350+
351+ public function testGetPropertyValueWithMethodAccess ()
352+ {
353+ $ product = new Product ();
354+ $ product ->setTitle ('Method Value ' );
355+
356+ $ field = new Property ('title ' );
357+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
358+
359+ $ this ->assertSame ('Method Value ' , $ result );
360+ }
361+
362+ public function testGetPropertyValueWithGetterAccess ()
363+ {
364+ $ product = new Product ();
365+ $ product ->setBody ('Body Content ' );
366+
367+ $ field = new Property ('body ' );
368+ $ result = $ this ->fieldEvaluator ->getValue ($ product , $ field );
369+
370+ $ this ->assertSame ('Body Content ' , $ result );
371+ }
228372}
0 commit comments