mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 07:09:24 +08:00
Use flarum/testing for test infrastructure (#2545)
This commit is contained in:
parent
bc607e089e
commit
2c3e1f9923
@ -67,8 +67,7 @@
|
||||
"wikimedia/less.php": "^3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.4",
|
||||
"phpunit/phpunit": "^9.0"
|
||||
"flarum/testing": "^0.1.0-beta.16"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Dflydev\FigCookies\SetCookie;
|
||||
use Illuminate\Support\Str;
|
||||
use Laminas\Diactoros\CallbackStream;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
|
||||
/**
|
||||
* A collection of helpers for building PSR-7 requests for integration tests.
|
||||
*/
|
||||
trait BuildsHttpRequests
|
||||
{
|
||||
protected function requestWithJsonBody(Request $req, array $json): Request
|
||||
{
|
||||
return $req
|
||||
->withHeader('Content-Type', 'application/json')
|
||||
->withBody(
|
||||
new CallbackStream(function () use ($json) {
|
||||
return json_encode($json);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
protected function requestAsUser(Request $req, int $userId): Request
|
||||
{
|
||||
$token = Str::random(40);
|
||||
|
||||
/**
|
||||
* We insert this directly instead of via `prepareDatabase`
|
||||
* so that requests can be created/sent after the app is booted.
|
||||
*/
|
||||
$this->database()->table('access_tokens')->insert([
|
||||
'token' => $token,
|
||||
'user_id' => $userId,
|
||||
'created_at' => Carbon::now()->toDateTimeString(),
|
||||
'last_activity_at' => Carbon::now()->toDateTimeString(),
|
||||
'type' => 'session'
|
||||
]);
|
||||
|
||||
return $req->withAddedHeader('Authorization', "Token {$token}");
|
||||
}
|
||||
|
||||
protected function requestWithCookiesFrom(Request $req, Response $previous): Request
|
||||
{
|
||||
$cookies = array_reduce(
|
||||
$previous->getHeader('Set-Cookie'),
|
||||
function ($memo, $setCookieString) {
|
||||
$setCookie = SetCookie::fromSetCookieString($setCookieString);
|
||||
$memo[$setCookie->getName()] = $setCookie->getValue();
|
||||
|
||||
return $memo;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
return $req->withCookieParams($cookies);
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration;
|
||||
|
||||
use Flarum\Foundation\Application;
|
||||
use Symfony\Component\Console\Application as ConsoleApplication;
|
||||
use Symfony\Component\Console\Input\ArrayInput;
|
||||
use Symfony\Component\Console\Output\BufferedOutput;
|
||||
|
||||
abstract class ConsoleTestCase extends TestCase
|
||||
{
|
||||
protected $console;
|
||||
|
||||
protected function console()
|
||||
{
|
||||
if (is_null($this->console)) {
|
||||
$this->console = new ConsoleApplication('Flarum', Application::VERSION);
|
||||
$this->console->setAutoExit(false);
|
||||
|
||||
foreach ($this->app()->getConsoleCommands() as $command) {
|
||||
$this->console->add($command);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->console;
|
||||
}
|
||||
|
||||
protected function runCommand(array $inputArray)
|
||||
{
|
||||
$input = new ArrayInput($inputArray);
|
||||
$output = new BufferedOutput();
|
||||
|
||||
$this->console()->run($input, $output);
|
||||
|
||||
return trim($output->fetch());
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration;
|
||||
|
||||
trait RetrievesAuthorizedUsers
|
||||
{
|
||||
protected function normalUser(): array
|
||||
{
|
||||
return [
|
||||
'id' => 2,
|
||||
'username' => 'normal',
|
||||
'password' => '$2y$10$LO59tiT7uggl6Oe23o/O6.utnF6ipngYjvMvaxo1TciKqBttDNKim', // BCrypt hash for "too-obscure"
|
||||
'email' => 'normal@machine.local',
|
||||
'is_email_confirmed' => 1,
|
||||
];
|
||||
}
|
||||
}
|
@ -1,204 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration;
|
||||
|
||||
use Flarum\Extend\ExtenderInterface;
|
||||
use Flarum\Foundation\Config;
|
||||
use Flarum\Foundation\InstalledSite;
|
||||
use Flarum\Foundation\Paths;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Laminas\Diactoros\ServerRequest;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
use BuildsHttpRequests;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown();
|
||||
|
||||
$this->database()->rollBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* @var \Flarum\Foundation\InstalledApp
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* @return \Flarum\Foundation\InstalledApp
|
||||
*/
|
||||
protected function app()
|
||||
{
|
||||
if (is_null($this->app)) {
|
||||
$site = new InstalledSite(
|
||||
new Paths([
|
||||
'base' => __DIR__.'/tmp',
|
||||
'vendor' => __DIR__.'/../../vendor',
|
||||
'public' => __DIR__.'/tmp/public',
|
||||
'storage' => __DIR__.'/tmp/storage',
|
||||
]),
|
||||
new Config(include __DIR__.'/tmp/config.php')
|
||||
);
|
||||
|
||||
$site->extendWith($this->extenders);
|
||||
|
||||
$this->app = $site->bootApp();
|
||||
|
||||
$this->database()->beginTransaction();
|
||||
|
||||
$this->populateDatabase();
|
||||
}
|
||||
|
||||
return $this->app;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var ExtenderInterface[]
|
||||
*/
|
||||
protected $extenders = [];
|
||||
|
||||
protected function extend(ExtenderInterface ...$extenders)
|
||||
{
|
||||
$this->extenders = array_merge($this->extenders, $extenders);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var RequestHandlerInterface
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
protected function server(): RequestHandlerInterface
|
||||
{
|
||||
if (is_null($this->server)) {
|
||||
$this->server = $this->app()->getRequestHandler();
|
||||
}
|
||||
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
protected $database;
|
||||
|
||||
protected function database(): ConnectionInterface
|
||||
{
|
||||
if (is_null($this->database)) {
|
||||
$this->database = $this->app()->getContainer()->make(
|
||||
ConnectionInterface::class
|
||||
);
|
||||
}
|
||||
|
||||
return $this->database;
|
||||
}
|
||||
|
||||
protected $databaseContent = [];
|
||||
|
||||
protected function prepareDatabase(array $tableData)
|
||||
{
|
||||
$this->databaseContent = array_merge_recursive(
|
||||
$this->databaseContent,
|
||||
$tableData
|
||||
);
|
||||
}
|
||||
|
||||
protected function populateDatabase()
|
||||
{
|
||||
// We temporarily disable foreign key checks to simplify this process.
|
||||
$this->database()->getSchemaBuilder()->disableForeignKeyConstraints();
|
||||
|
||||
// Then, insert all rows required for this test case.
|
||||
foreach ($this->databaseContent as $table => $rows) {
|
||||
foreach ($rows as $row) {
|
||||
if ($table === 'settings') {
|
||||
$this->database()->table($table)->updateOrInsert(
|
||||
['key' => $row['key']],
|
||||
$row
|
||||
);
|
||||
} else {
|
||||
$this->database()->table($table)->updateOrInsert(
|
||||
isset($row['id']) ? ['id' => $row['id']] : $row,
|
||||
$row
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// And finally, turn on foreign key checks again.
|
||||
$this->database()->getSchemaBuilder()->enableForeignKeyConstraints();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a full HTTP request through Flarum's middleware stack.
|
||||
*/
|
||||
protected function send(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
return $this->server()->handle($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a HTTP request that can be passed through middleware.
|
||||
*
|
||||
* This method simplifies building HTTP requests for use in our HTTP-level
|
||||
* integration tests. It provides options for all features repeatedly being
|
||||
* used in those tests.
|
||||
*
|
||||
* @param string $method
|
||||
* @param string $path
|
||||
* @param array $options
|
||||
* An array of optional request properties.
|
||||
* Currently supported:
|
||||
* - "json" should point to a JSON-serializable object that will be
|
||||
* serialized and used as request body. The corresponding Content-Type
|
||||
* header will be set automatically.
|
||||
* - "authenticatedAs" should identify an *existing* user by ID. This will
|
||||
* cause an access token to be created for this user, which will be used
|
||||
* to authenticate the request via the "Authorization" header.
|
||||
* - "cookiesFrom" should hold a response object from a previous HTTP
|
||||
* interaction. All cookies returned from the server in that response
|
||||
* (via the "Set-Cookie" header) will be copied to the cookie params of
|
||||
* the new request.
|
||||
* @return ServerRequestInterface
|
||||
*/
|
||||
protected function request(string $method, string $path, array $options = []): ServerRequestInterface
|
||||
{
|
||||
$request = new ServerRequest([], [], $path, $method);
|
||||
|
||||
// Do we want a JSON request body?
|
||||
if (isset($options['json'])) {
|
||||
$request = $this->requestWithJsonBody(
|
||||
$request,
|
||||
$options['json']
|
||||
);
|
||||
}
|
||||
|
||||
// Authenticate as a given user
|
||||
if (isset($options['authenticatedAs'])) {
|
||||
$request = $this->requestAsUser(
|
||||
$request,
|
||||
$options['authenticatedAs']
|
||||
);
|
||||
}
|
||||
|
||||
// Let's copy the cookies from a previous response
|
||||
if (isset($options['cookiesFrom'])) {
|
||||
$request = $this->requestWithCookiesFrom(
|
||||
$request,
|
||||
$options['cookiesFrom']
|
||||
);
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\integration;
|
||||
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
|
||||
trait UsesSettings
|
||||
{
|
||||
/**
|
||||
* Removes the settings respository instance from the IoC container.
|
||||
*
|
||||
* This allows test cases that add/modify settings to refresh the in-memory settings cache.
|
||||
*/
|
||||
protected function purgeSettingsCache()
|
||||
{
|
||||
$this->app()->getContainer()->forgetInstance(SettingsRepositoryInterface::class);
|
||||
}
|
||||
}
|
@ -11,8 +11,8 @@ namespace Flarum\Tests\integration\api\access_tokens;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Http\AccessToken;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Laminas\Diactoros\ServerRequest;
|
||||
|
||||
class AccessTokenLifecycleTest extends TestCase
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\access_tokens;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class RemembererTest extends TestCase
|
||||
{
|
||||
|
@ -11,8 +11,8 @@ namespace Flarum\Tests\integration\api\authentication;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Api\ApiKey;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class WithApiKeyTest extends TestCase
|
||||
{
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\authentication;
|
||||
|
||||
use Flarum\Http\AccessToken;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class WithTokenTest extends TestCase
|
||||
{
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
namespace Flarum\Tests\integration\api\csrf_protection;
|
||||
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class RequireCsrfTokenTest extends TestCase
|
||||
{
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\discussions;
|
||||
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class CreateTest extends TestCase
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\discussions;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class DeletionTest extends TestCase
|
||||
{
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\discussions;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\discussions;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class ListTest extends TestCase
|
||||
{
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\discussions;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class ShowTest extends TestCase
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
namespace Flarum\Tests\integration\api\forum;
|
||||
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class ShowTest extends TestCase
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\groups;
|
||||
|
||||
use Flarum\Group\Group;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class CreateTest extends TestCase
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
namespace Flarum\Tests\integration\api\groups;
|
||||
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class ListTest extends TestCase
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
namespace Flarum\Tests\integration\api\notifications;
|
||||
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class ListTest extends TestCase
|
||||
{
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\posts;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class CreateTest extends TestCase
|
||||
{
|
||||
|
@ -11,8 +11,8 @@ namespace Flarum\Tests\integration\api\posts;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Event\ConfigurePostsQuery;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class ListTests extends TestCase
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\users;
|
||||
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
|
||||
class CreateTest extends TestCase
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
namespace Flarum\Tests\integration\api\users;
|
||||
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class GroupSearchTest extends TestCase
|
||||
{
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
namespace Flarum\Tests\integration\api\users;
|
||||
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class ListTest extends TestCase
|
||||
|
@ -9,8 +9,8 @@
|
||||
|
||||
namespace Flarum\Tests\integration\api\users;
|
||||
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class ShowTest extends TestCase
|
||||
{
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\api\users;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class UpdateTest extends TestCase
|
||||
{
|
||||
|
@ -22,8 +22,8 @@ use Flarum\Api\Serializer\PostSerializer;
|
||||
use Flarum\Api\Serializer\UserSerializer;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
|
@ -19,8 +19,8 @@ use Flarum\Api\Serializer\UserSerializer;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
|
||||
class ApiSerializerTest extends TestCase
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
|
||||
class AuthTest extends TestCase
|
||||
|
@ -11,7 +11,7 @@ namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Console\AbstractCommand;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\ConsoleTestCase;
|
||||
use Flarum\Testing\integration\ConsoleTestCase;
|
||||
|
||||
class ConsoleTest extends ConsoleTestCase
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
|
||||
class CsrfTest extends TestCase
|
||||
|
@ -13,8 +13,8 @@ use Flarum\Extend;
|
||||
use Flarum\Foundation\Application;
|
||||
use Flarum\Group\Command\CreateGroup;
|
||||
use Flarum\Group\Event\Created;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
@ -14,8 +14,8 @@ use Flarum\Discussion\Filter\DiscussionFilterer;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Filter\FilterInterface;
|
||||
use Flarum\Filter\FilterState;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class FilterTest extends TestCase
|
||||
{
|
||||
|
@ -11,7 +11,7 @@ namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Formatter\Formatter;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class FormatterTest extends TestCase
|
||||
{
|
||||
|
@ -12,8 +12,8 @@ namespace Flarum\Tests\integration\extenders;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Mail\DriverInterface;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Swift_NullTransport;
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
|
@ -11,8 +11,8 @@ namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
|
||||
class ModelPrivateTest extends TestCase
|
||||
|
@ -17,8 +17,8 @@ use Flarum\Post\AbstractEventPost;
|
||||
use Flarum\Post\CommentPost;
|
||||
use Flarum\Post\DiscussionRenamedPost;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
|
||||
class ModelTest extends TestCase
|
||||
|
@ -13,9 +13,9 @@ use Flarum\Database\AbstractModel;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Http\SlugDriverInterface;
|
||||
use Flarum\Http\SlugManager;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Tests\integration\UsesSettings;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\Testing\integration\UsesSettings;
|
||||
use Flarum\User\User;
|
||||
|
||||
class ModelUrlTest extends TestCase
|
||||
|
@ -14,8 +14,8 @@ use Flarum\Discussion\Discussion;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Post\CommentPost;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Arr;
|
||||
|
@ -14,8 +14,8 @@ use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\Driver\NotificationDriverInterface;
|
||||
use Flarum\Notification\Notification;
|
||||
use Flarum\Notification\NotificationSyncer;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
|
||||
class NotificationTest extends TestCase
|
||||
|
@ -14,9 +14,9 @@ use Flarum\Discussion\Discussion;
|
||||
use Flarum\Extend;
|
||||
use Flarum\Post\CommentPost;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\Tests\integration\BuildsHttpRequests;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\BuildsHttpRequests;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\Access\AbstractPolicy;
|
||||
use Flarum\User\User;
|
||||
|
||||
|
@ -13,7 +13,7 @@ use Flarum\Extend;
|
||||
use Flarum\Post\AbstractEventPost;
|
||||
use Flarum\Post\MergeableInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class PostTest extends TestCase
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Laminas\Diactoros\Response\TextResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
|
@ -11,7 +11,7 @@ namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Foundation\AbstractServiceProvider;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class ServiceProviderTest extends TestCase
|
||||
{
|
||||
|
@ -10,9 +10,9 @@
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Tests\integration\UsesSettings;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\Testing\integration\UsesSettings;
|
||||
|
||||
class SettingsTest extends TestCase
|
||||
{
|
||||
|
@ -16,8 +16,8 @@ use Flarum\Query\QueryCriteria;
|
||||
use Flarum\Search\AbstractRegexGambit;
|
||||
use Flarum\Search\GambitInterface;
|
||||
use Flarum\Search\SearchState;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\User;
|
||||
|
||||
class SimpleFlarumSearchTest extends TestCase
|
||||
|
@ -10,8 +10,8 @@
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
|
||||
class ThrottleApiTest extends TestCase
|
||||
{
|
||||
|
@ -10,9 +10,9 @@
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Tests\integration\UsesSettings;
|
||||
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\Testing\integration\UsesSettings;
|
||||
use Flarum\User\DisplayName\DriverInterface;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Support\Arr;
|
||||
|
@ -11,7 +11,7 @@ namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Group\GroupValidator;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Flarum\User\UserValidator;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\integration\extenders;
|
||||
|
||||
use Flarum\Extend;
|
||||
use Flarum\Tests\integration\TestCase;
|
||||
use Flarum\Testing\integration\TestCase;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
|
||||
class ViewTest extends TestCase
|
||||
|
@ -7,65 +7,10 @@
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\Install\AdminUser;
|
||||
use Flarum\Install\BaseUrl;
|
||||
use Flarum\Install\DatabaseConfig;
|
||||
use Flarum\Install\Installation;
|
||||
use Flarum\Testing\integration\Setup\SetupScript;
|
||||
|
||||
require __DIR__.'/../../vendor/autoload.php';
|
||||
|
||||
$host = getenv('DB_HOST') ?: 'localhost';
|
||||
$port = intval(getenv('DB_PORT') ?: 3306);
|
||||
$name = getenv('DB_DATABASE') ?: 'flarum_test';
|
||||
$user = getenv('DB_USERNAME') ?: 'root';
|
||||
$pass = getenv('DB_PASSWORD') ?: '';
|
||||
$pref = getenv('DB_PREFIX') ?: '';
|
||||
$setup = new SetupScript();
|
||||
|
||||
echo "Connecting to database $name at $host:$port.\n";
|
||||
echo "Logging in as $user with password '$pass'.\n";
|
||||
echo "Table prefix: '$pref'\n";
|
||||
|
||||
echo "\n\nCancel now if that's not what you want...\n";
|
||||
echo "Use the following environment variables for configuration:\n";
|
||||
echo "DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, DB_PASSWORD, DB_PREFIX\n";
|
||||
|
||||
sleep(5);
|
||||
|
||||
echo "\nOff we go...\n";
|
||||
|
||||
/*
|
||||
* Setup installation configuration
|
||||
*/
|
||||
|
||||
$installation = new Installation(
|
||||
new Paths([
|
||||
'base' => __DIR__.'/tmp',
|
||||
'public' => __DIR__.'/tmp/public',
|
||||
'storage' => __DIR__.'/tmp/storage',
|
||||
'vendor' => __DIR__.'/../../vendor',
|
||||
])
|
||||
);
|
||||
|
||||
$pipeline = $installation
|
||||
->configPath('config.php')
|
||||
->debugMode(true)
|
||||
->baseUrl(BaseUrl::fromString('http://localhost'))
|
||||
->databaseConfig(
|
||||
new DatabaseConfig('mysql', $host, $port, $name, $user, $pass, $pref)
|
||||
)
|
||||
->adminUser(new AdminUser(
|
||||
'admin',
|
||||
'password',
|
||||
'admin@machine.local'
|
||||
))
|
||||
->settings(['mail_driver' => 'log'])
|
||||
->build();
|
||||
|
||||
/*
|
||||
* Run the actual configuration
|
||||
*/
|
||||
|
||||
$pipeline->run();
|
||||
|
||||
echo "Installation complete\n";
|
||||
$setup->run();
|
||||
|
@ -1 +0,0 @@
|
||||
{}
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\unit\Foundation;
|
||||
|
||||
use Flarum\Foundation\Config;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\unit\Foundation;
|
||||
|
||||
use Flarum\Foundation\ContainerUtil;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
use Illuminate\Container\Container;
|
||||
|
||||
class ContainerUtilTest extends TestCase
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\unit\Foundation\ErrorHandling\ExceptionHandler;
|
||||
|
||||
use Flarum\Foundation\ErrorHandling\ExceptionHandler\IlluminateValidationExceptionHandler;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
use Illuminate\Translation\ArrayLoader;
|
||||
use Illuminate\Translation\Translator;
|
||||
use Illuminate\Validation\Factory;
|
||||
|
@ -11,7 +11,7 @@ namespace Flarum\Tests\unit\Foundation\ErrorHandling\ExceptionHandler;
|
||||
|
||||
use Flarum\Foundation\ErrorHandling\ExceptionHandler\ValidationExceptionHandler;
|
||||
use Flarum\Foundation\ValidationException;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
|
||||
class ValidationExceptionHandlerTest extends TestCase
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\unit\Foundation;
|
||||
|
||||
use Flarum\Extension\ExtensionManager;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
|
||||
class ExtensionDependencyResolutionTest extends TestCase
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\unit\Foundation;
|
||||
|
||||
use Flarum\Foundation\Paths;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class PathsTest extends TestCase
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\unit\Foundation;
|
||||
|
||||
use Flarum\Http\RouteCollection;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
class RouteCollectionTest extends TestCase
|
||||
|
@ -12,7 +12,7 @@ namespace Flarum\Tests\unit\Http;
|
||||
use Carbon\Carbon;
|
||||
use Flarum\Foundation\Config;
|
||||
use Flarum\Http\CookieFactory;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
|
||||
class CookieFactoryTest extends TestCase
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\unit\Http;
|
||||
|
||||
use Flarum\Http\RouteCollection;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
|
||||
class RouteCollectionTest extends TestCase
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\unit\Install;
|
||||
|
||||
use Flarum\Install\BaseUrl;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
use Laminas\Diactoros\Uri;
|
||||
|
||||
class BaseUrlTest extends TestCase
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\unit\Install\Prerequisite;
|
||||
|
||||
use Flarum\Install\Prerequisite\WritablePaths;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
|
||||
class WritablePathsTest extends TestCase
|
||||
{
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace Flarum\Tests\unit\Settings;
|
||||
|
||||
use Flarum\Settings\DatabaseSettingsRepository;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
use Illuminate\Database\ConnectionInterface;
|
||||
use Mockery as m;
|
||||
|
||||
|
@ -11,7 +11,7 @@ namespace Flarum\Tests\unit\Settings;
|
||||
|
||||
use Flarum\Settings\MemoryCacheSettingsRepository;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
use Mockery as m;
|
||||
|
||||
class MemoryCacheSettingsRepositoryTest extends TestCase
|
||||
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* For detailed copyright and license information, please view the
|
||||
* LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Tests\unit;
|
||||
|
||||
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
|
||||
|
||||
abstract class TestCase extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
// Ensure Mockery is always torn down automatically after each test.
|
||||
use MockeryPHPUnitIntegration;
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace Flarum\Tests\unit\User;
|
||||
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
use Flarum\User\Access\AbstractPolicy;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace Flarum\Tests\unit\User;
|
||||
|
||||
use Flarum\Tests\unit\TestCase;
|
||||
use Flarum\Testing\unit\TestCase;
|
||||
use Flarum\User\AvatarUploader;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
Loading…
x
Reference in New Issue
Block a user