Skip to content

Commit

Permalink
[10.x] Fix parallel testing without any database connection (#47705)
Browse files Browse the repository at this point in the history
* Fix parallel testing without any database connection

* StyleCI
  • Loading branch information
deleugpn authored Jul 10, 2023
1 parent 921e956 commit 33ca6fc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Testing/Concerns/TestDatabases.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ protected function usingDatabase($database, $callable)
*/
protected function whenNotUsingInMemoryDatabase($callback)
{
if (ParallelTesting::option('without_databases')) {
return;
}

$database = DB::getConfig('database');

if ($database !== ':memory:') {
Expand Down
29 changes: 29 additions & 0 deletions tests/Integration/Testing/TestWithoutDatabaseParallelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Illuminate\Tests\Integration\Testing;

use Illuminate\Support\Facades\ParallelTesting;
use Illuminate\Testing\ParallelTestingServiceProvider;
use Orchestra\Testbench\TestCase;

class TestWithoutDatabaseParallelTest extends TestCase
{
protected function getPackageProviders($app)
{
return [ParallelTestingServiceProvider::class];
}

public function testRunningParallelTestWithoutDatabaseShouldNotCrashOnDefaultConnection()
{
// Given an application that does not use database connections at all
$this->app['config']->set('database.default', null);

// When we run parallel testing with `without-databases` option
$_SERVER['LARAVEL_PARALLEL_TESTING'] = 1;
$_SERVER['LARAVEL_PARALLEL_TESTING_WITHOUT_DATABASES'] = 1;
$_SERVER['TEST_TOKEN'] = '1';

// We should not create a database connection to check if it's SQLite or not.
ParallelTesting::callSetUpProcessCallbacks();
}
}

0 comments on commit 33ca6fc

Please sign in to comment.