@@ -186,6 +186,35 @@ public function testSetNestedElement($class)
186186 $ this ->assertSame (Arr::setNestedElement ([], '[].[].[] ' , 'test ' ), Arr::set ([], '[].[].[] ' , 'test ' ));
187187 $ this ->assertSame (Arr::setNestedElement ($ array , 'test.test2.test3 ' , 'abc ' ), Arr::set ($ array , 'test.test2.test3 ' , 'abc ' ));
188188 $ this ->assertSame (Arr::setNestedElement ($ array , 'key1.key2 ' , ['key3 ' => 'test ' ]), Arr::set ($ array , 'key1.key2 ' , ['key3 ' => 'test ' ]));
189+
190+ // Test ArrayAccess
191+
192+ $ obj3 = new ArrayObject ([
193+ 'c ' => [
194+ 'd ' => 1 ,
195+ ],
196+ ]);
197+ $ array = [
198+ 'test ' => [
199+ 'a ' => [
200+ 'b ' => $ obj3 ,
201+ 'test2 '
202+ ],
203+ ],
204+ ];
205+
206+ $ array = $ this ->callMethod ([$ class , 'set ' ], $ array , 'test.a.b.c.d ' , 2 );
207+ $ this ->assertSame (2 , $ array ['test ' ]['a ' ]['b ' ]['c ' ]['d ' ]);
208+
209+ $ array = $ this ->callMethod ([$ class , 'set ' ], $ array , 'test.a.b.foo ' , 'bar ' );
210+ $ this ->assertSame ('bar ' , $ array ['test ' ]['a ' ]['b ' ]['foo ' ]);
211+
212+ $ array = $ this ->callMethod ([$ class , 'set ' ], $ array , 'test.a.b.x.[] ' , 'xyz ' );
213+ $ this ->assertSame ('xyz ' , $ array ['test ' ]['a ' ]['b ' ]['x ' ][0 ]);
214+
215+ // Test pure array object set
216+ $ obj3 = $ this ->callMethod ([$ class , 'set ' ], $ obj3 , 'c.[].test ' , true );
217+ $ this ->assertSame (true , $ obj3 ['c ' ][0 ]['test ' ]);
189218 }
190219
191220 /**
0 commit comments