Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Fix parallel testing without any database connection #47705

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}