Skip to content

Commit 33ca6fc

Browse files
authored
[10.x] Fix parallel testing without any database connection (#47705)
* Fix parallel testing without any database connection * StyleCI
1 parent 921e956 commit 33ca6fc

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Illuminate/Testing/Concerns/TestDatabases.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ protected function usingDatabase($database, $callable)
141141
*/
142142
protected function whenNotUsingInMemoryDatabase($callback)
143143
{
144+
if (ParallelTesting::option('without_databases')) {
145+
return;
146+
}
147+
144148
$database = DB::getConfig('database');
145149

146150
if ($database !== ':memory:') {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Testing;
4+
5+
use Illuminate\Support\Facades\ParallelTesting;
6+
use Illuminate\Testing\ParallelTestingServiceProvider;
7+
use Orchestra\Testbench\TestCase;
8+
9+
class TestWithoutDatabaseParallelTest extends TestCase
10+
{
11+
protected function getPackageProviders($app)
12+
{
13+
return [ParallelTestingServiceProvider::class];
14+
}
15+
16+
public function testRunningParallelTestWithoutDatabaseShouldNotCrashOnDefaultConnection()
17+
{
18+
// Given an application that does not use database connections at all
19+
$this->app['config']->set('database.default', null);
20+
21+
// When we run parallel testing with `without-databases` option
22+
$_SERVER['LARAVEL_PARALLEL_TESTING'] = 1;
23+
$_SERVER['LARAVEL_PARALLEL_TESTING_WITHOUT_DATABASES'] = 1;
24+
$_SERVER['TEST_TOKEN'] = '1';
25+
26+
// We should not create a database connection to check if it's SQLite or not.
27+
ParallelTesting::callSetUpProcessCallbacks();
28+
}
29+
}

0 commit comments

Comments
 (0)