55namespace Ray \InputQuery ;
66
77use ArrayObject ;
8+ use InvalidArgumentException ;
89use PHPUnit \Framework \TestCase ;
910use Ray \Di \Injector ;
1011use Ray \InputQuery \Attribute \Input ;
@@ -152,11 +153,8 @@ public function testArrayWithNonArrayElements(): void
152153 {
153154 $ query = [
154155 'users ' => [
155- 'string-value ' ,
156- 123 ,
156+ 'string-value ' , // Non-array element at index 0
157157 ['id ' => '1 ' , 'name ' => 'valid ' ],
158- null ,
159- true ,
160158 ],
161159 ];
162160
@@ -170,13 +168,11 @@ public function listUsers(
170168 };
171169
172170 $ method = new ReflectionMethod ($ controller , 'listUsers ' );
173- $ args = $ this ->inputQuery ->getArguments ($ method , $ query );
174171
175- $ this ->assertIsArray ($ args [0 ]);
176- $ this ->assertCount (1 , $ args [0 ]); // Only the valid array element
177- $ this ->assertInstanceOf (UserInputWithAttribute::class, $ args [0 ][2 ]);
178- $ this ->assertSame ('1 ' , $ args [0 ][2 ]->id );
179- $ this ->assertSame ('valid ' , $ args [0 ][2 ]->name );
172+ $ this ->expectException (InvalidArgumentException::class);
173+ $ this ->expectExceptionMessage ('Expected array for item at key "0", got string. ' );
174+
175+ $ this ->inputQuery ->getArguments ($ method , $ query );
180176 }
181177
182178 public function testCustomArrayObjectOfInputObjects (): void
@@ -216,4 +212,28 @@ public function listUsers(
216212 $ this ->assertInstanceOf (UserInputWithAttribute::class, $ firstUser );
217213 $ this ->assertSame ('5 ' , $ firstUser ->id );
218214 }
215+
216+ public function testArrayObjectWithoutItemAttribute (): void
217+ {
218+ $ query = [
219+ 'users ' => [
220+ ['id ' => '1 ' , 'name ' => 'test ' ],
221+ ],
222+ ];
223+
224+ $ controller = new class {
225+ public function listUsers (
226+ #[Input] // No item parameter specified
227+ ArrayObject $ users ,
228+ ): ArrayObject {
229+ return $ users ;
230+ }
231+ };
232+
233+ $ method = new ReflectionMethod ($ controller , 'listUsers ' );
234+ $ args = $ this ->inputQuery ->getArguments ($ method , $ query );
235+
236+ // Should create a regular ArrayObject with the nested query data
237+ $ this ->assertInstanceOf (ArrayObject::class, $ args [0 ]);
238+ }
219239}
0 commit comments