mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Added initial support for parallel testing
This commit is contained in:
@ -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\Support\Facades\DB;
|
||||
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.
|
||||
* 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)
|
||||
{
|
||||
@ -311,7 +314,12 @@ abstract class TestCase extends BaseTestCase
|
||||
$_SERVER[$name] = $value;
|
||||
}
|
||||
|
||||
$database = config('database.connections.mysql_testing.database');
|
||||
$this->refreshApplication();
|
||||
|
||||
DB::purge();
|
||||
config()->set('database.connections.mysql_testing.database', $database);
|
||||
|
||||
$callback();
|
||||
|
||||
if (is_null($originalVal)) {
|
||||
|
@ -322,8 +322,8 @@ class ThemeTest extends TestCase
|
||||
|
||||
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();
|
||||
|
||||
@ -342,18 +342,18 @@ class ThemeTest extends TestCase
|
||||
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('');
|
||||
|
||||
// Create theme folder and clean it up on application tear-down
|
||||
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);
|
||||
});
|
||||
|
||||
// Cleanup the custom theme folder we created
|
||||
File::deleteDirectory($themeFolderPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user