Skip to content

Conversation

@cosmastech
Copy link
Contributor

@cosmastech cosmastech commented Nov 13, 2025

I'll be honest, I'm not entirely sure why this has fixed the problem described here. #57663 (comment) I've stepped through this many times and I am still lost about what this change is preventing from happening. I can see it has something to do with caching the config before calling the parallel testing provider, but... yeah, I'm still a touch confused.

For whatever it's worth, I thought that I wanted to set the application to cached before booting to avoid a disk read on LoadEnvironmentVariables, however, TIL that Env keeps a static instance of the environment variables stored. Turns out that wasn't necessary.

Thanks to @santigarcor for bringing this to my attention.

@SanderMuller
Copy link
Contributor

@cosmastech I tried this change locally in our project, and it causes errors in some tests, for example a test that renders a page containing a NoCaptcha from the https://github.com/anhskohbo/no-captcha package.

Specifically on GuzzleHttp\Client::__construct(): Argument #1 ($config) must be of type array, null given from Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::register()

    public function register()
    {
        $this->app->singleton('captcha', function ($app) {
            return new NoCaptcha(
                $app['config']['captcha.secret'],
                $app['config']['captcha.sitekey'],
                $app['config']['captcha.options']
            );
        });
    }

This test works fine with $this->markConfigCached($app);

@cosmastech
Copy link
Contributor Author

@cosmastech I tried this change locally in our project, and it causes errors in some tests, for example a test that renders a page containing a NoCaptcha from the https://github.com/anhskohbo/no-captcha package.

Specifically on GuzzleHttp\Client::__construct(): Argument #1 ($config) must be of type array, null given from Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::register()

    public function register()
    {
        $this->app->singleton('captcha', function ($app) {
            return new NoCaptcha(
                $app['config']['captcha.secret'],
                $app['config']['captcha.sitekey'],
                $app['config']['captcha.options']
            );
        });
    }

This test works fine with $this->markConfigCached($app);

Thanks for reporting this @SanderMuller. I will mark this as draft and continue my spelunking.

@cosmastech cosmastech marked this pull request as draft November 14, 2025 11:00
Comment on lines +196 to +200
if (! isset(self::$originalDatabaseName)) {
self::$originalDatabaseName = $database;
} else {
$database = self::$originalDatabaseName;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I think that this trait/approach needs refactored to work with multiple database connections. Currently, I don't believe that multiple connections are seeded/migrated. This approach is a little bit naive and assumes (like the rest of the parallel runner code) that there's but a single database to be concerned with.

@cosmastech cosmastech marked this pull request as ready for review November 14, 2025 15:12
@taylorotwell taylorotwell merged commit 4ae5893 into laravel:12.x Nov 14, 2025
66 checks passed
@cosmastech cosmastech deleted the patch-28 branch November 15, 2025 16:18
@marickvantuil
Copy link

Our application has multiple parallel connections (to make it work we used the steps in this tutorial) but after this change our test suite breaks. I think it currently doesn't work with multiple connections.

@cosmastech
Copy link
Contributor Author

cosmastech commented Nov 19, 2025

Our application has multiple parallel connections (to make it work we used the steps in this tutorial) but after this change our test suite breaks. I think it currently doesn't work with multiple connections.

Yes, as noted above, the ParallelTestRunner isn't designed out of the box to work with multiple connections. Strangely enough, we have (almost) this exact tutorial code in our codebase. For whatever reason, we never ran into the parallel runner problem that others reported.

Can you try adding this to your extended service provider, replacing your testDatabaseOnConnection() method?

    private static array $connectionMap = [];
    protected function testDatabaseOnConnection(string $connection): string
    {
        if (! isset(self::$connectionMap[$connection])) {
            self::$connectionMap[$connection] = config("database.connections.$connection.database");
        }

        self::$originalDatabaseName = self::$connectionMap[$connection];

        return $this->testDatabase(config("database.connections.$connection.database"));
    }

@marickvantuil
Copy link

Thanks @cosmastech! It sadly didn't work. I don't have time to investigate further, but from a quick test I see that the underlying testDatabase method is still being called somewhere and returning a stale database name.

Screenshot 2025-11-19 at 13 52 31

I've 'solved' it for now by overwriting the testDatabase function and keeping it's original behavior:

protected function testDatabase($database): string
{
    $token = ParallelTesting::token();

    return "{$database}_test_{$token}";
}

@cosmastech
Copy link
Contributor Author

Thanks @cosmastech! It sadly didn't work. I don't have time to investigate further, but from a quick test I see that the underlying testDatabase method is still being called somewhere and returning a stale database name.

Screenshot 2025-11-19 at 13 52 31 I've 'solved' it for now by overwriting the `testDatabase` function and keeping it's original behavior:
protected function testDatabase($database): string
{
    $token = ParallelTesting::token();

    return "{$database}_test_{$token}";
}

Glad you've got it working for the time being. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants