Skip to content

Commit

Permalink
[8.x] Allow parallel testing without database creation (#38143)
Browse files Browse the repository at this point in the history
* Allow parallel testing without database copying

* Remove pointless wrap of optional recreate_databases

* formatting'

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
uintaam and taylorotwell authored Jul 27, 2021
1 parent 67b5182 commit 9d8bf0a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Illuminate/Testing/Concerns/TestDatabases.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,21 @@ protected function bootTestDatabase()
];

if (Arr::hasAny($uses, $databaseTraits)) {
$this->whenNotUsingInMemoryDatabase(function ($database) use ($uses) {
[$testDatabase, $created] = $this->ensureTestDatabaseExists($database);
if (! ParallelTesting::option('without_databases')) {
$this->whenNotUsingInMemoryDatabase(function ($database) use ($uses) {
[$testDatabase, $created] = $this->ensureTestDatabaseExists($database);

$this->switchToDatabase($testDatabase);
$this->switchToDatabase($testDatabase);

if (isset($uses[Testing\DatabaseTransactions::class])) {
$this->ensureSchemaIsUpToDate();
}
if (isset($uses[Testing\DatabaseTransactions::class])) {
$this->ensureSchemaIsUpToDate();
}

if ($created) {
ParallelTesting::callSetUpTestDatabaseCallbacks($testDatabase);
}
});
if ($created) {
ParallelTesting::callSetUpTestDatabaseCallbacks($testDatabase);
}
});
}
}
});
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Testing/ParallelTestingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,21 @@ public function testOptions()
$parallelTesting = new ParallelTesting(Container::getInstance());

$this->assertFalse($parallelTesting->option('recreate_databases'));
$this->assertFalse($parallelTesting->option('without_databases'));

$parallelTesting->resolveOptionsUsing(function ($option) {
return $option === 'recreate_databases';
});

$this->assertFalse($parallelTesting->option('recreate_caches'));
$this->assertFalse($parallelTesting->option('without_databases'));
$this->assertTrue($parallelTesting->option('recreate_databases'));

$parallelTesting->resolveOptionsUsing(function ($option) {
return $option === 'without_databases';
});

$this->assertTrue($parallelTesting->option('without_databases'));
}

public function testToken()
Expand Down

0 comments on commit 9d8bf0a

Please sign in to comment.