From a03dcd4e3f0b610327c81bde206d389ba06d01de Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sun, 11 Oct 2015 23:37:51 +1030 Subject: [PATCH] Fix failing tests + CS --- .../src/Api/Relationship/HasManyBuilder.php | 1 - framework/core/src/Core/Access/Gate.php | 24 ++++++++++--------- framework/core/src/Core/Access/UserPolicy.php | 1 - ...php => RequireAdministrateAbilityTest.php} | 12 ++++++---- .../DatabaseSettingsRepositoryTest.php | 4 ++-- 5 files changed, 22 insertions(+), 20 deletions(-) rename framework/core/tests/Flarum/Admin/Middleware/{LoginWithCookieAndCheckAdminTest.php => RequireAdministrateAbilityTest.php} (60%) diff --git a/framework/core/src/Api/Relationship/HasManyBuilder.php b/framework/core/src/Api/Relationship/HasManyBuilder.php index 24134739b..d7af2e8cc 100644 --- a/framework/core/src/Api/Relationship/HasManyBuilder.php +++ b/framework/core/src/Api/Relationship/HasManyBuilder.php @@ -33,4 +33,3 @@ class HasManyBuilder extends AbstractHasManyBuilder $this->actor = $actor; } } - diff --git a/framework/core/src/Core/Access/Gate.php b/framework/core/src/Core/Access/Gate.php index bdd2288f1..ccb1baf54 100644 --- a/framework/core/src/Core/Access/Gate.php +++ b/framework/core/src/Core/Access/Gate.php @@ -183,9 +183,7 @@ class Gate implements GateContract return $result; } - $callback = $this->resolveAuthCallback( - $user, $ability, $arguments - ); + $callback = $this->resolveAuthCallback($user, $ability, $arguments); return call_user_func_array($callback, array_merge([$user], $arguments)); } @@ -224,7 +222,9 @@ class Gate implements GateContract } elseif (isset($this->abilities[$ability])) { return $this->abilities[$ability]; } else { - return function () { return false; }; + return function () { + return false; + }; } } @@ -266,9 +266,7 @@ class Gate implements GateContract // into the policy before methods with the arguments and get the result. $beforeArguments = array_merge([$user, $ability], $arguments); - $result = call_user_func_array( - [$instance, 'before'], $beforeArguments - ); + $result = call_user_func_array([$instance, 'before'], $beforeArguments); // If we recieved a non-null result from the before method, we will return it // as the result of a check. This allows developers to override the checks @@ -282,9 +280,7 @@ class Gate implements GateContract return false; } - return call_user_func_array( - [$instance, $ability], array_merge([$user], $arguments) - ); + return call_user_func_array([$instance, $ability], array_merge([$user], $arguments)); }; } @@ -329,7 +325,13 @@ class Gate implements GateContract public function forUser($user) { return new static( - $this->container, function () use ($user) { return $user; }, $this->abilities, $this->policies, $this->beforeCallbacks + $this->container, + function () use ($user) { + return $user; + }, + $this->abilities, + $this->policies, + $this->beforeCallbacks ); } diff --git a/framework/core/src/Core/Access/UserPolicy.php b/framework/core/src/Core/Access/UserPolicy.php index cc31dc948..6daf97c87 100644 --- a/framework/core/src/Core/Access/UserPolicy.php +++ b/framework/core/src/Core/Access/UserPolicy.php @@ -31,4 +31,3 @@ class UserPolicy extends AbstractPolicy } } } - diff --git a/framework/core/tests/Flarum/Admin/Middleware/LoginWithCookieAndCheckAdminTest.php b/framework/core/tests/Flarum/Admin/Middleware/RequireAdministrateAbilityTest.php similarity index 60% rename from framework/core/tests/Flarum/Admin/Middleware/LoginWithCookieAndCheckAdminTest.php rename to framework/core/tests/Flarum/Admin/Middleware/RequireAdministrateAbilityTest.php index e03ee7085..607000928 100644 --- a/framework/core/tests/Flarum/Admin/Middleware/LoginWithCookieAndCheckAdminTest.php +++ b/framework/core/tests/Flarum/Admin/Middleware/RequireAdministrateAbilityTest.php @@ -2,6 +2,8 @@ namespace tests\Flarum\Admin\Middleware; use Flarum\Admin\Middleware\AuthenticateWithCookie; +use Flarum\Admin\Middleware\RequireAdministrateAbility; +use Flarum\Core\Access\Gate; use Flarum\Core\Exception\PermissionDeniedException; use Illuminate\Contracts\Container\Container; use Mockery as m; @@ -9,19 +11,19 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use tests\Test\TestCase; -class LoginWithCookieAndCheckAdminTest extends TestCase +class RequireAdministrateAbilityTest extends TestCase { public function test_it_should_not_allow_invalid_logins() { $this->setExpectedException(PermissionDeniedException::class); - $container = m::mock(Container::class); - $request = m::mock(ServerRequestInterface::class); + $gate = m::mock(Gate::class); + $request = m::mock(ServerRequestInterface::class)->shouldIgnoreMissing(); $response = m::mock(ResponseInterface::class); - $request->shouldReceive('getCookieParams')->andReturn([]); + $gate->shouldReceive('forUser->allows')->andReturn(false); - $middleware = new AuthenticateWithCookie($container); + $middleware = new RequireAdministrateAbility($gate); $middleware->__invoke($request, $response); } } diff --git a/framework/core/tests/Flarum/Core/Settings/DatabaseSettingsRepositoryTest.php b/framework/core/tests/Flarum/Core/Settings/DatabaseSettingsRepositoryTest.php index 3d901b890..3e7929dc1 100644 --- a/framework/core/tests/Flarum/Core/Settings/DatabaseSettingsRepositoryTest.php +++ b/framework/core/tests/Flarum/Core/Settings/DatabaseSettingsRepositoryTest.php @@ -19,14 +19,14 @@ class DatabaseSettingsRepositoryTest extends TestCase public function test_requesting_an_existing_setting_should_return_its_value() { - $this->connection->shouldReceive("table->where->pluck")->andReturn('value'); + $this->connection->shouldReceive("table->where->value")->andReturn('value'); $this->assertEquals('value', $this->repository->get('key')); } public function test_non_existent_setting_values_should_return_null() { - $this->connection->shouldReceive("table->where->pluck")->andReturn(null); + $this->connection->shouldReceive("table->where->value")->andReturn(null); $this->assertEquals('default', $this->repository->get('key', 'default')); }