Skip to content

Commit

Permalink
Merge pull request #224 from abenerd/feature/drop-databases-parallel-…
Browse files Browse the repository at this point in the history
…flag

Add drop databases flag for parity with laravel
  • Loading branch information
nunomaduro authored Apr 5, 2022
2 parents 7534dd6 + dd82302 commit f3f9498
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Adapters/Laravel/Commands/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
';

/**
Expand Down Expand Up @@ -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'))) {
Expand Down Expand Up @@ -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'),
];
}

Expand Down
1 change: 1 addition & 0 deletions tests/LaravelApp/app/Console/Commands/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}
';

Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/Adapters/ArtisanTestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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']);
}

/**
Expand All @@ -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
Expand Down

0 comments on commit f3f9498

Please sign in to comment.