Fix failing tests + CS

This commit is contained in:
Toby Zerner 2015-10-11 23:37:51 +10:30
parent 0af6df7f95
commit a03dcd4e3f
5 changed files with 22 additions and 20 deletions

View File

@ -33,4 +33,3 @@ class HasManyBuilder extends AbstractHasManyBuilder
$this->actor = $actor;
}
}

View File

@ -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
);
}

View File

@ -31,4 +31,3 @@ class UserPolicy extends AbstractPolicy
}
}
}

View File

@ -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);
}
}

View File

@ -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'));
}