mirror of
https://github.com/flarum/core.git
synced 2025-07-30 21:20:24 +02:00
Make integration tests independent
This creates a dedicated test suite for integration tests. All of them can be run independently, and there is no order dependency - previously, all integration tests needed the installer test to run first, and they would fail if installation failed. Now, the developer will have to set up a Flarum database to be used by these tests. A setup script to make this simple will be added in the next commit. Small tradeoff: the installer is NOT tested in our test suite anymore, only implicitly through the setup script. If we decide that this is a problem, we can still set up separate, dedicated installer tests which should probably test the web installer.
This commit is contained in:
@@ -13,9 +13,12 @@ namespace Flarum\Tests\integration\api\Auth;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Api\ApiKey;
|
||||
use Flarum\Api\Client;
|
||||
use Flarum\Api\Controller\CreateGroupController;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\User\Guest;
|
||||
use Flarum\User\User;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
@@ -28,6 +31,18 @@ class AuthenticateWithApiKeyTest extends TestCase
|
||||
{
|
||||
use RetrievesAuthorizedUsers;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->prepareDatabase([
|
||||
'users' => [
|
||||
$this->adminUser(),
|
||||
$this->normalUser(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
protected function key(int $user_id = null): ApiKey
|
||||
{
|
||||
return ApiKey::unguarded(function () use ($user_id) {
|
||||
@@ -45,9 +60,11 @@ class AuthenticateWithApiKeyTest extends TestCase
|
||||
*/
|
||||
public function cannot_authorize_without_key()
|
||||
{
|
||||
$this->call(
|
||||
CreateGroupController::class
|
||||
);
|
||||
/** @var Client $api */
|
||||
$api = $this->app()->getContainer()->make(Client::class);
|
||||
$api->setErrorHandler(null);
|
||||
|
||||
$api->send(CreateGroupController::class, new Guest);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,7 +96,7 @@ class AuthenticateWithApiKeyTest extends TestCase
|
||||
*/
|
||||
public function personal_api_token_cannot_authenticate_as_anyone()
|
||||
{
|
||||
$user = $this->getNormalUser();
|
||||
$user = User::find(2);
|
||||
|
||||
$key = $this->key($user->id);
|
||||
|
||||
@@ -105,7 +122,7 @@ class AuthenticateWithApiKeyTest extends TestCase
|
||||
*/
|
||||
public function personal_api_token_authenticates_user()
|
||||
{
|
||||
$user = $this->getNormalUser();
|
||||
$user = User::find(2);
|
||||
|
||||
$key = $this->key($user->id);
|
||||
|
||||
|
Reference in New Issue
Block a user