@@ -57,6 +57,11 @@ class MyPresenter
5757 public function objects (stdClass $ req , ?stdClass $ nullable , stdClass $ opt = null )
5858 {
5959 }
60+
61+
62+ public function hintsUnion (int |array $ intArray , string |array $ strArray )
63+ {
64+ }
6065}
6166
6267
@@ -252,3 +257,27 @@ test('', function () {
252257 Reflection::combineArgs ($ method , ['req ' => [], 'opt ' => null ]);
253258 }, Nette \InvalidArgumentException::class, 'Argument $req passed to MyPresenter::objects() must be stdClass, array given. ' );
254259});
260+
261+
262+ test ('' , function () {
263+ $ method = new ReflectionMethod ('MyPresenter ' , 'hintsUnion ' );
264+
265+ Assert::same ([1 , 'abc ' ], Reflection::combineArgs ($ method , ['intArray ' => '1 ' , 'strArray ' => 'abc ' ]));
266+ Assert::same ([[1 ], [2 ]], Reflection::combineArgs ($ method , ['intArray ' => [1 ], 'strArray ' => [2 ]]));
267+
268+ Assert::exception (function () use ($ method ) {
269+ Reflection::combineArgs ($ method , []);
270+ }, Nette \InvalidArgumentException::class, 'Missing parameter $intArray required by MyPresenter::hintsUnion() ' );
271+
272+ Assert::exception (function () use ($ method ) {
273+ Reflection::combineArgs ($ method , ['intArray ' => '' ]);
274+ }, Nette \InvalidArgumentException::class, 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, string given. ' );
275+
276+ Assert::exception (function () use ($ method ) {
277+ Reflection::combineArgs ($ method , ['intArray ' => null ]);
278+ }, Nette \InvalidArgumentException::class, 'Missing parameter $intArray required by MyPresenter::hintsUnion() ' );
279+
280+ Assert::exception (function () use ($ method ) {
281+ Reflection::combineArgs ($ method , ['intArray ' => new stdClass ]);
282+ }, Nette \InvalidArgumentException::class, 'Argument $intArray passed to MyPresenter::hintsUnion() must be array|int, stdClass given. ' );
283+ });
0 commit comments