mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-23 04:10:22 +00:00
Cleaned testing service provider usage
Moved testing content out of AppServiceProvider, to a testing-specific service provider. Updated docs and added composer commands to support parallel testing. Also reverted unintentional change to wysiwyg/config.js.
This commit is contained in:
parent
e18033ec1a
commit
f21669c0c9
6 changed files with 46 additions and 15 deletions
|
@ -17,9 +17,7 @@ use GuzzleHttp\Client;
|
||||||
use Illuminate\Contracts\Cache\Repository;
|
use Illuminate\Contracts\Cache\Repository;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
use Illuminate\Pagination\Paginator;
|
use Illuminate\Pagination\Paginator;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
|
||||||
use Illuminate\Support\Facades\Blade;
|
use Illuminate\Support\Facades\Blade;
|
||||||
use Illuminate\Support\Facades\ParallelTesting;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Support\Facades\URL;
|
use Illuminate\Support\Facades\URL;
|
||||||
use Illuminate\Support\Facades\View;
|
use Illuminate\Support\Facades\View;
|
||||||
|
@ -66,11 +64,6 @@ class AppServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
// Set paginator to use bootstrap-style pagination
|
// Set paginator to use bootstrap-style pagination
|
||||||
Paginator::useBootstrap();
|
Paginator::useBootstrap();
|
||||||
|
|
||||||
// Setup database upon parallel testing database creation
|
|
||||||
ParallelTesting::setUpTestDatabase(function ($database, $token) {
|
|
||||||
Artisan::call('db:seed --class=DummyContentSeeder');
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -74,6 +74,8 @@
|
||||||
"format": "phpcbf",
|
"format": "phpcbf",
|
||||||
"lint": "phpcs",
|
"lint": "phpcs",
|
||||||
"test": "phpunit",
|
"test": "phpunit",
|
||||||
|
"t": "@php artisan test --parallel",
|
||||||
|
"t-reset": "@php artisan test --recreate-databases",
|
||||||
"post-autoload-dump": [
|
"post-autoload-dump": [
|
||||||
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
|
||||||
"@php artisan package:discover --ansi"
|
"@php artisan package:discover --ansi"
|
||||||
|
|
|
@ -108,14 +108,9 @@ npm run dev
|
||||||
|
|
||||||
BookStack has many integration tests that use Laravel's built-in testing capabilities which makes use of PHPUnit. There is a `mysql_testing` database defined within the app config which is what is used by PHPUnit. This database is set with the database name, user name and password all defined as `bookstack-test`. You will have to create that database and that set of credentials before testing.
|
BookStack has many integration tests that use Laravel's built-in testing capabilities which makes use of PHPUnit. There is a `mysql_testing` database defined within the app config which is what is used by PHPUnit. This database is set with the database name, user name and password all defined as `bookstack-test`. You will have to create that database and that set of credentials before testing.
|
||||||
|
|
||||||
The testing database will also need migrating and seeding beforehand. This can be done with the following commands:
|
The testing database will also need migrating and seeding beforehand. This can be done by running `composer refresh-test-database`.
|
||||||
|
|
||||||
``` bash
|
Once done you can run `composer test` in the application root directory to run all tests. Tests can be ran in parallel by running them via `composer t`. This will use Laravel's built-in parallel testing functionality, and attempt to create and seed a database instance for each testing thread. If required these parallel testing instances can be reset, before testing again, by running `composer t-reset`.
|
||||||
php artisan migrate --database=mysql_testing
|
|
||||||
php artisan db:seed --class=DummyContentSeeder --database=mysql_testing
|
|
||||||
```
|
|
||||||
|
|
||||||
Once done you can run `composer test` in the application root directory to run all tests.
|
|
||||||
|
|
||||||
### 📜 Code Standards
|
### 📜 Code Standards
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,6 @@ export function build(options) {
|
||||||
document_base_url: window.baseUrl('/'),
|
document_base_url: window.baseUrl('/'),
|
||||||
end_container_on_empty_block: true,
|
end_container_on_empty_block: true,
|
||||||
remove_trailing_brs: false,
|
remove_trailing_brs: false,
|
||||||
keep_styles: false,
|
|
||||||
statusbar: false,
|
statusbar: false,
|
||||||
menubar: false,
|
menubar: false,
|
||||||
paste_data_images: false,
|
paste_data_images: false,
|
||||||
|
|
|
@ -22,6 +22,7 @@ use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Handler\MockHandler;
|
use GuzzleHttp\Handler\MockHandler;
|
||||||
use GuzzleHttp\HandlerStack;
|
use GuzzleHttp\HandlerStack;
|
||||||
use GuzzleHttp\Middleware;
|
use GuzzleHttp\Middleware;
|
||||||
|
use Illuminate\Contracts\Console\Kernel;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
|
@ -48,6 +49,21 @@ abstract class TestCase extends BaseTestCase
|
||||||
*/
|
*/
|
||||||
protected string $baseUrl = 'http://localhost';
|
protected string $baseUrl = 'http://localhost';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the application.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Foundation\Application
|
||||||
|
*/
|
||||||
|
public function createApplication()
|
||||||
|
{
|
||||||
|
/** @var \Illuminate\Foundation\Application $app */
|
||||||
|
$app = require __DIR__ . '/../bootstrap/app.php';
|
||||||
|
$app->register(TestServiceProvider::class);
|
||||||
|
$app->make(Kernel::class)->bootstrap();
|
||||||
|
|
||||||
|
return $app;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the current user context to be an admin.
|
* Set the current user context to be an admin.
|
||||||
*/
|
*/
|
||||||
|
|
26
tests/TestServiceProvider.php
Normal file
26
tests/TestServiceProvider.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Illuminate\Support\Facades\ParallelTesting;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class TestServiceProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bootstrap services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
// Tell Laravel's parallel testing functionality to seed the test
|
||||||
|
// databases with the DummyContentSeeder upon creation.
|
||||||
|
// This is only done for initial database creation. Seeding
|
||||||
|
// won't occur on every run.
|
||||||
|
ParallelTesting::setUpTestDatabase(function ($database, $token) {
|
||||||
|
Artisan::call('db:seed --class=DummyContentSeeder');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue