diff --git a/src/Illuminate/Auth/Access/Gate.php b/src/Illuminate/Auth/Access/Gate.php index 78946ea94ecf..20506daa98f3 100644 --- a/src/Illuminate/Auth/Access/Gate.php +++ b/src/Illuminate/Auth/Access/Gate.php @@ -462,14 +462,12 @@ protected function callAuthCallback($user, $ability, array $arguments) */ protected function callBeforeCallbacks($user, $ability, array $arguments) { - $arguments = array_merge([$user, $ability], [$arguments]); - foreach ($this->beforeCallbacks as $before) { if (! $this->canBeCalledWithUser($user, $before)) { continue; } - if (! is_null($result = $before(...$arguments))) { + if (! is_null($result = $before($user, $ability, $arguments))) { return $result; } } diff --git a/tests/Auth/AuthAccessGateTest.php b/tests/Auth/AuthAccessGateTest.php index 175b7401df8d..35da87779851 100644 --- a/tests/Auth/AuthAccessGateTest.php +++ b/tests/Auth/AuthAccessGateTest.php @@ -342,12 +342,22 @@ public function test_a_single_argument_can_be_passed_when_checking_abilities() $dummy = new AccessGateTestDummy; + $gate->before(function ($user, $ability, array $arguments) use ($dummy) { + $this->assertCount(1, $arguments); + $this->assertSame($dummy, $arguments[0]); + }); + $gate->define('foo', function ($user, $x) use ($dummy) { - $this->assertEquals($dummy, $x); + $this->assertSame($dummy, $x); return true; }); + $gate->after(function ($user, $ability, $result, array $arguments) use ($dummy) { + $this->assertCount(1, $arguments); + $this->assertSame($dummy, $arguments[0]); + }); + $this->assertTrue($gate->check('foo', $dummy)); } @@ -358,13 +368,23 @@ public function test_multiple_arguments_can_be_passed_when_checking_abilities() $dummy1 = new AccessGateTestDummy; $dummy2 = new AccessGateTestDummy; + $gate->before(function ($user, $ability, array $arguments) use ($dummy1, $dummy2) { + $this->assertCount(2, $arguments); + $this->assertSame([$dummy1, $dummy2], $arguments); + }); + $gate->define('foo', function ($user, $x, $y) use ($dummy1, $dummy2) { - $this->assertEquals($dummy1, $x); - $this->assertEquals($dummy2, $y); + $this->assertSame($dummy1, $x); + $this->assertSame($dummy2, $y); return true; }); + $gate->after(function ($user, $ability, $result, array $arguments) use ($dummy1, $dummy2) { + $this->assertCount(2, $arguments); + $this->assertSame([$dummy1, $dummy2], $arguments); + }); + $this->assertTrue($gate->check('foo', [$dummy1, $dummy2])); }