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

Default connection is being changed unreliably in testing #51163

Closed
olieady opened this issue Apr 22, 2024 · 1 comment · Fixed by #51167
Closed

Default connection is being changed unreliably in testing #51163

olieady opened this issue Apr 22, 2024 · 1 comment · Fixed by #51167
Labels

Comments

@olieady
Copy link

olieady commented Apr 22, 2024

Laravel Version

11.4

PHP Version

8.2

Database Driver & Version

Mysql 8.1

Description

When providing a custom connection to the FreshCommand it is changing the application's default connection.

https://github.com/laravel/framework/blob/11.x/src/Illuminate/Database/Console/Migrations/FreshCommand.php#L65-L67

This was introduced in 11.4 by this PR - #51021

setConnection doesn't reset the default connection back to its original, unlike usingConnection.

Steps To Reproduce

<?php

namespace Tests\Feature;

use Tests\TestCase;

class ExampleTest extends TestCase
{
    /**
     * A basic feature test example.
     */
    public function test_example(): void
    {
        $this->artisan('migrate:fresh', [
            '--database' => 'non_default_connection',
        ]);

        dd(config('database.default'));
    }
}

Laravel 11.3 output - "mysql" // tests/Feature/ExampleTest.php:18
Laravel 11.4 output - "non_default_connection" // tests/Feature/ExampleTest.php:18

@driesvints
Copy link
Member

Thanks for reporting! I've sent in a PR for this: #51167

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants