use Illuminate\Contracts\Cache\Repository;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Pagination\Paginator;
-use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Blade;
-use Illuminate\Support\Facades\ParallelTesting;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\View;
// Set paginator to use bootstrap-style pagination
Paginator::useBootstrap();
-
- // Setup database upon parallel testing database creation
- ParallelTesting::setUpTestDatabase(function ($database, $token) {
- Artisan::call('db:seed --class=DummyContentSeeder');
- });
}
/**
"format": "phpcbf",
"lint": "phpcs",
"test": "phpunit",
+ "t": "@php artisan test --parallel",
+ "t-reset": "@php artisan test --recreate-databases",
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
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
-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.
+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`.
### 📜 Code Standards
document_base_url: window.baseUrl('/'),
end_container_on_empty_block: true,
remove_trailing_brs: false,
- keep_styles: false,
statusbar: false,
menubar: false,
paste_data_images: false,
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
+use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Illuminate\Http\JsonResponse;
*/
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.
*/
--- /dev/null
+<?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');
+ });
+ }
+}