Skip to content

Commit

Permalink
added tests plus bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
imanghafoori1 committed May 30, 2021
1 parent 26927db commit 02feaad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/Plugins/Reactions/WeRespondFrom.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 7 additions & 2 deletions tests/Stubs/SomeClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
18 changes: 16 additions & 2 deletions tests/reactionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

0 comments on commit 02feaad

Please sign in to comment.