]> BookStack Code Mirror - bookstack/commitdiff
Added initial support for parallel testing
authorDan Brown <redacted>
Mon, 26 Sep 2022 20:25:32 +0000 (21:25 +0100)
committerDan Brown <redacted>
Mon, 26 Sep 2022 20:25:32 +0000 (21:25 +0100)
app/Providers/AppServiceProvider.php
composer.json
resources/js/wysiwyg/config.js
tests/TestCase.php
tests/ThemeTest.php

index 3c1212e3274d5b23a42da1f8d9df26a1630bcdc8..02c545db23cdb2597fe1f70ceb03efc8a932c4c7 100644 (file)
@@ -17,7 +17,9 @@ use GuzzleHttp\Client;
 use Illuminate\Contracts\Cache\Repository;
 use Illuminate\Database\Eloquent\Relations\Relation;
 use Illuminate\Pagination\Paginator;
 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\Blade;
+use Illuminate\Support\Facades\ParallelTesting;
 use Illuminate\Support\Facades\Schema;
 use Illuminate\Support\Facades\URL;
 use Illuminate\Support\Facades\View;
 use Illuminate\Support\Facades\Schema;
 use Illuminate\Support\Facades\URL;
 use Illuminate\Support\Facades\View;
@@ -64,6 +66,11 @@ class AppServiceProvider extends ServiceProvider
 
         // Set paginator to use bootstrap-style pagination
         Paginator::useBootstrap();
 
         // 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');
+        });
     }
 
     /**
     }
 
     /**
index 64630833d66b92378f72d4bb428bfa4a6b20dc5e..44bbf2b99fd012d2ac4b821f6c151a75e994f85d 100644 (file)
@@ -44,6 +44,7 @@
         "ssddanbrown/htmldiff": "^1.0.2"
     },
     "require-dev": {
         "ssddanbrown/htmldiff": "^1.0.2"
     },
     "require-dev": {
+        "brianium/paratest": "^6.6",
         "fakerphp/faker": "^1.16",
         "itsgoingd/clockwork": "^5.1",
         "mockery/mockery": "^1.4",
         "fakerphp/faker": "^1.16",
         "itsgoingd/clockwork": "^5.1",
         "mockery/mockery": "^1.4",
index 52c52592cb720fab6a235a5d04ea4902cbf89515..d2f813cfbfede1e07881fa206fb1a12442911237 100644 (file)
@@ -252,6 +252,7 @@ export function build(options) {
         document_base_url: window.baseUrl('/'),
         end_container_on_empty_block: true,
         remove_trailing_brs: false,
         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,
         statusbar: false,
         menubar: false,
         paste_data_images: false,
index f17d27a1aa320fe4ae4e0bc50ade126ae326302f..0926b0dcc171d9367ead165995ace45fa779bf31 100644 (file)
@@ -26,6 +26,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
 use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
 use Illuminate\Http\JsonResponse;
 use Illuminate\Support\Env;
 use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
 use Illuminate\Http\JsonResponse;
 use Illuminate\Support\Env;
+use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Testing\Assert as PHPUnit;
 use Monolog\Handler\TestHandler;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Testing\Assert as PHPUnit;
 use Monolog\Handler\TestHandler;
@@ -299,6 +300,8 @@ abstract class TestCase extends BaseTestCase
     /**
      * Run a set test with the given env variable.
      * Remembers the original and resets the value after test.
     /**
      * Run a set test with the given env variable.
      * Remembers the original and resets the value after test.
+     * Database config is juggled so the value can be restored when
+     * parallel testing are used, where multiple databases exist.
      */
     protected function runWithEnv(string $name, $value, callable $callback)
     {
      */
     protected function runWithEnv(string $name, $value, callable $callback)
     {
@@ -311,7 +314,12 @@ abstract class TestCase extends BaseTestCase
             $_SERVER[$name] = $value;
         }
 
             $_SERVER[$name] = $value;
         }
 
+        $database = config('database.connections.mysql_testing.database');
         $this->refreshApplication();
         $this->refreshApplication();
+
+        DB::purge();
+        config()->set('database.connections.mysql_testing.database', $database);
+
         $callback();
 
         if (is_null($originalVal)) {
         $callback();
 
         if (is_null($originalVal)) {
index e83758a956ef3bc9cc6472e9b6502d7881759717..ac4b35de2029d070482c36f06db63e6b6fe7ce09 100644 (file)
@@ -322,8 +322,8 @@ class ThemeTest extends TestCase
 
     public function test_export_body_start_and_end_template_files_can_be_used()
     {
 
     public function test_export_body_start_and_end_template_files_can_be_used()
     {
-        $bodyStartStr = 'barry-fought-against-the-panther';
-        $bodyEndStr = 'barry-lost-his-fight-with-grace';
+        $bodyStartStr = 'garry-fought-against-the-panther';
+        $bodyEndStr = 'garry-lost-his-fight-with-grace';
         /** @var Page $page */
         $page = Page::query()->first();
 
         /** @var Page $page */
         $page = Page::query()->first();
 
@@ -342,18 +342,18 @@ class ThemeTest extends TestCase
     protected function usingThemeFolder(callable $callback)
     {
         // Create a folder and configure a theme
     protected function usingThemeFolder(callable $callback)
     {
         // Create a folder and configure a theme
-        $themeFolderName = 'testing_theme_' . rtrim(base64_encode(time()), '=');
+        $themeFolderName = 'testing_theme_' . str_shuffle(rtrim(base64_encode(time()), '='));
         config()->set('view.theme', $themeFolderName);
         $themeFolderPath = theme_path('');
         config()->set('view.theme', $themeFolderName);
         $themeFolderPath = theme_path('');
+
+        // Create theme folder and clean it up on application tear-down
         File::makeDirectory($themeFolderPath);
         File::makeDirectory($themeFolderPath);
+        $this->beforeApplicationDestroyed(fn() => File::deleteDirectory($themeFolderPath));
 
         // Run provided callback with theme env option set
         $this->runWithEnv('APP_THEME', $themeFolderName, function () use ($callback, $themeFolderName) {
             call_user_func($callback, $themeFolderName);
         });
 
         // Run provided callback with theme env option set
         $this->runWithEnv('APP_THEME', $themeFolderName, function () use ($callback, $themeFolderName) {
             call_user_func($callback, $themeFolderName);
         });
-
-        // Cleanup the custom theme folder we created
-        File::deleteDirectory($themeFolderPath);
     }
 }
 
     }
 }