Skip to content

Commit

Permalink
Adds "--refresh-databases" option
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Jan 12, 2021
1 parent 59ec9d0 commit d6ec142
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/Adapters/Laravel/Commands/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class TestCommand extends Command
*/
protected $signature = 'test
{--without-tty : Disable output to TTY}
{--parallel : Whether the tests should be run in parallel}
{--parallel : Indicates if the tests should run in parallel}
{--refresh-databases : Indicates if the test databases should be re-created}
';

/**
Expand Down Expand Up @@ -96,7 +97,10 @@ public function handle()
),
null,
// Envs ...
$parallel ? ['LARAVEL_PARALLEL_TESTING' => 1] : [],
$parallel ? [
'LARAVEL_PARALLEL_TESTING' => 1,
'LARAVEL_PARALLEL_TESTING_REFRESH_DATABASES' => $this->option('refresh-databases'),
] : [],
))->setTimeout(null);

try {
Expand Down Expand Up @@ -175,7 +179,8 @@ protected function paratestArguments($options)
{
$options = array_values(array_filter($options, function ($option) {
return !Str::startsWith($option, '--env=')
&& !Str::startsWith($option, '--parallel');
&& !Str::startsWith($option, '--parallel')
&& !Str::startsWith($option, '--refresh-databases');
}));

if (!file_exists($file = base_path('phpunit.xml'))) {
Expand Down
12 changes: 12 additions & 0 deletions tests/LaravelApp/app/Console/Commands/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ class TestCommand extends BaseTestCommand
*/
protected function binary()
{
switch (true) {
case $this->option('parallel'):
$command = 'vendor/brianium/paratest/bin/paratest';
break;
case class_exists(\Pest\Laravel\PestServiceProvider::class):
$command = 'vendor/pestphp/pest/bin/pest';
break;
default:
$command = 'vendor/phpunit/phpunit/phpunit';
break;
}

if ('phpdbg' === PHP_SAPI) {
return [PHP_BINARY, '-qrr', __DIR__ . '/../../../../../vendor/bin/phpunit'];
}
Expand Down
2 changes: 0 additions & 2 deletions tests/Unit/Adapters/ArtisanTestCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public function testEnv(): void
]);

$this->runTests(['./tests/LaravelApp/artisan', 'test', '--group', 'environment']);
$this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--group', 'environment']);
}

/** @test */
Expand All @@ -43,7 +42,6 @@ public function testEnvTesting(): void
]);

$this->runTests(['./tests/LaravelApp/artisan', 'test', '--group', 'environmentTesting']);
$this->runTests(['./tests/LaravelApp/artisan', 'test', '--parallel', '--group', 'environmentTesting']);
}

/**
Expand Down

0 comments on commit d6ec142

Please sign in to comment.