@@ -573,12 +573,28 @@ public static function getValidReadPropertyPaths(): iterable
573
573
yield [(object ) ['foo ' => null ], 'foo?.bar.baz ' , null ];
574
574
yield [(object ) ['foo ' => (object ) ['bar ' => null ]], 'foo?.bar?.baz ' , null ];
575
575
yield [(object ) ['foo ' => (object ) ['bar ' => null ]], 'foo.bar?.baz ' , null ];
576
+
577
+ yield from self ::getNullSafeIndexPaths ();
578
+ }
579
+
580
+ public static function getNullSafeIndexPaths (): iterable
581
+ {
576
582
yield [(object ) ['foo ' => ['bar ' => null ]], 'foo[bar?].baz ' , null ];
577
583
yield [[], '[foo?] ' , null ];
578
584
yield [['foo ' => ['firstName ' => 'Bernhard ' ]], '[foo][bar?] ' , null ];
579
585
yield [['foo ' => ['firstName ' => 'Bernhard ' ]], '[foo][bar?][baz?] ' , null ];
580
586
}
581
587
588
+ /**
589
+ * @dataProvider getNullSafeIndexPaths
590
+ */
591
+ public function testNullSafeIndexWithThrowOnInvalidIndex ($ objectOrArray , $ path , $ value )
592
+ {
593
+ $ this ->propertyAccessor = new PropertyAccessor (PropertyAccessor::DISALLOW_MAGIC_METHODS , PropertyAccessor::THROW_ON_INVALID_INDEX | PropertyAccessor::THROW_ON_INVALID_PROPERTY_PATH );
594
+
595
+ $ this ->assertSame ($ value , $ this ->propertyAccessor ->getValue ($ objectOrArray , $ path ));
596
+ }
597
+
582
598
public function testTicket5755 ()
583
599
{
584
600
$ object = new Ticket5775Object ();
0 commit comments