From dd8230291acc4dd82684086c4e4427ec63c43de0 Mon Sep 17 00:00:00 2001 From: abenerd Date: Mon, 4 Apr 2022 20:44:15 +0200 Subject: [PATCH] feat: add drop databases flag for parallel tests --- src/Adapters/Laravel/Commands/TestCommand.php | 5 ++++- tests/LaravelApp/app/Console/Commands/TestCommand.php | 1 + tests/Unit/Adapters/ArtisanTestCommandTest.php | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Adapters/Laravel/Commands/TestCommand.php b/src/Adapters/Laravel/Commands/TestCommand.php index f1a35063..43595f1b 100644 --- a/src/Adapters/Laravel/Commands/TestCommand.php +++ b/src/Adapters/Laravel/Commands/TestCommand.php @@ -34,6 +34,7 @@ class TestCommand extends Command {--min= : Indicates the minimum threshold enforcement for code coverage} {--p|parallel : Indicates if the tests should run in parallel} {--recreate-databases : Indicates if the test databases should be re-created} + {--drop-databases : Indicates if the test databases should be dropped} '; /** @@ -238,7 +239,8 @@ protected function paratestArguments($options) && !Str::startsWith($option, '--min') && !Str::startsWith($option, '-p') && !Str::startsWith($option, '--parallel') - && !Str::startsWith($option, '--recreate-databases'); + && !Str::startsWith($option, '--recreate-databases') + && !Str::startsWith($option, '--drop-databases'); })); if (!file_exists($file = base_path('phpunit.xml'))) { @@ -271,6 +273,7 @@ protected function paratestEnvironmentVariables() return [ 'LARAVEL_PARALLEL_TESTING' => 1, 'LARAVEL_PARALLEL_TESTING_RECREATE_DATABASES' => $this->option('recreate-databases'), + 'LARAVEL_PARALLEL_TESTING_DROP_DATABASES' => $this->option('drop-databases'), ]; } diff --git a/tests/LaravelApp/app/Console/Commands/TestCommand.php b/tests/LaravelApp/app/Console/Commands/TestCommand.php index 21a5d838..6df0ccd8 100644 --- a/tests/LaravelApp/app/Console/Commands/TestCommand.php +++ b/tests/LaravelApp/app/Console/Commands/TestCommand.php @@ -20,6 +20,7 @@ class TestCommand extends BaseTestCommand {--min= : Indicates the minimum threshold enforcement for coverage} {--p|parallel : Indicates if the tests should run in parallel} {--recreate-databases : Indicates if the test databases should be re-created} + {--drop-databases : Indicates if the test databases should be dropped} {--c|custom-argument : Add custom env variables} '; diff --git a/tests/Unit/Adapters/ArtisanTestCommandTest.php b/tests/Unit/Adapters/ArtisanTestCommandTest.php index a969e802..d81b7b4d 100644 --- a/tests/Unit/Adapters/ArtisanTestCommandTest.php +++ b/tests/Unit/Adapters/ArtisanTestCommandTest.php @@ -61,6 +61,7 @@ public function testEnv(): void $this->runTests(['./tests/LaravelApp/artisan', 'test', '--group', 'environment']); $this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--group', 'environment']); $this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--recreate-databases', '--group', 'environment']); + $this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--drop-databases', '--group', 'environment']); } /** @test */ @@ -83,6 +84,7 @@ public function testEnvTesting(): void $this->runTests(['./tests/LaravelApp/artisan', 'test', '--group', 'environmentTesting']); $this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--group', 'environmentTesting']); $this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--recreate-databases', '--group', 'environmentTesting']); + $this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--drop-databases', '--group', 'environmentTesting']); } /** @@ -108,16 +110,19 @@ public function testExtendableCustomVariables(): void $this->runTests(['./tests/LaravelApp/artisan', 'test', '--group', 'environmentNoCVPhpunit']); $this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--group', 'environmentNoCVParallel']); $this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--recreate-databases', '--group', 'environmentNoCVParallelRecreate']); + $this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--drop-databases', '--group', 'environmentNoCVParallelRecreate']); // With Custom Variables (-c) $this->runTests(['./tests/LaravelApp/artisan', 'test', '-c', '--group', 'environmentCVPhpunit']); $this->runTests(['./tests/LaravelApp/artisan', 'test', '-c', '--parallel', '--group', 'environmentCVParallel']); $this->runTests(['./tests/LaravelApp/artisan', 'test', '-c', '--parallel', '--recreate-databases', '--group', 'environmentCVParallelRecreate']); + $this->runTests(['./tests/LaravelApp/artisan', 'test', '-c', '--parallel', '--drop-databases', '--group', 'environmentCVParallelRecreate']); // With Custom Variables (--custom-argument) $this->runTests(['./tests/LaravelApp/artisan', 'test', '--custom-argument', '--group', 'environmentCVPhpunit']); $this->runTests(['./tests/LaravelApp/artisan', 'test', '--custom-argument', '--parallel', '--group', 'environmentCVParallel']); $this->runTests(['./tests/LaravelApp/artisan', 'test', '--custom-argument', '--parallel', '--recreate-databases', '--group', 'environmentCVParallelRecreate']); + $this->runTests(['./tests/LaravelApp/artisan', 'test', '--custom-argument', '--parallel', '--drop-databases', '--group', 'environmentCVParallelRecreate']); } private function runTests(array $arguments, int $expectedExitCode = 0): string