diff --git a/src/Plugins/Reactions/WeRespondFrom.php b/src/Plugins/Reactions/WeRespondFrom.php index bf76588..b998701 100644 --- a/src/Plugins/Reactions/WeRespondFrom.php +++ b/src/Plugins/Reactions/WeRespondFrom.php @@ -19,8 +19,7 @@ public static function respondFrom($method) { return function () use ($method) { if (is_array($method[0])) { - $method[] = []; - $response = call_user_func_array(...$method); + $response = call_user_func_array($method[0], $method[1] ?? []); } else { $response = app()->call(...$method); } diff --git a/tests/Stubs/SomeClass.php b/tests/Stubs/SomeClass.php index 6d9d359..33fe81d 100644 --- a/tests/Stubs/SomeClass.php +++ b/tests/Stubs/SomeClass.php @@ -14,8 +14,13 @@ public function someMethod2($p1, $p2) return response()->json(['Wow' => (string) ($p1 + $p2)], 566); } - public static function someStaticMethod() + public static function someStaticMethod($p1, $p2) { - return response()->json(['Wow' => 'Man'], 201); + return response()->json(['Wow' => (string) ($p1 + $p2)], 201); + } + + public static function someStaticMethod_2() + { + return response()->json(['Wow' => 'aaa'], 201); } } diff --git a/tests/reactionsTest.php b/tests/reactionsTest.php index 901e7cd..cb2a728 100644 --- a/tests/reactionsTest.php +++ b/tests/reactionsTest.php @@ -111,10 +111,24 @@ public function test_we_respond_from_2() HeyMan::whenYouVisitUrl('welcome') ->thisValueShouldAllow(false) ->otherwise() - ->weRespondFrom([SomeClass::class, 'someStaticMethod']); + ->weRespondFrom([SomeClass::class, 'someStaticMethod'], [20, 30]); app(StartGuarding::class)->start(); - $this->get('welcome')->assertStatus(201)->assertJson(['Wow'=> 'Man']); + $this->get('welcome')->assertStatus(201)->assertJson(['Wow'=> '50']); + } + + public function test_we_respond_from_3() + { + Route::get('/welcome', 'HomeController@index'); + + HeyMan::whenYouVisitUrl('welcome') + ->thisValueShouldAllow(false) + ->otherwise() + ->weRespondFrom([SomeClass::class, 'someStaticMethod_2']); + + app(StartGuarding::class)->start(); + + $this->get('welcome')->assertStatus(201)->assertJson(['Wow' => 'aaa']); } }