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

[9.x] Add the beforeRefreshingDatabase function to the Testing/RefreshDatabase trait #42073

Merged
merged 1 commit into from
Apr 21, 2022
Merged

[9.x] Add the beforeRefreshingDatabase function to the Testing/RefreshDatabase trait #42073

merged 1 commit into from
Apr 21, 2022

Conversation

roksprogar
Copy link
Contributor

@roksprogar roksprogar commented Apr 21, 2022

Type: Improvement

This pull request adds beforeRefreshingDatabase to Testing/RefreshDatabase trait.

Use Case

When using the refreshDatabase trait in my feature tests, I needed to run the php artisan db:wipe --database another-database-connection before the migrations were run, or the migrations kept failing with "table already exists" - because the other database wasn't wiped beforehand. With the added beforeRefreshingDatabase function, I was able to wipe out the other database in any of my tests like this:

class DataExportTest extends TestCase
{
    use RefreshDatabase;

    protected $seed = true;

    protected function beforeRefreshingDatabase()
    {
        $this->artisan('db:wipe --database another-database-connection');
    }

    public function test_prepare_some_data()
    {
        ...
    }
}

I think this function could be useful to other developers as well, because it allows for running just about anything before the database is refreshed.

@taylorotwell taylorotwell merged commit 8c737f0 into laravel:9.x Apr 21, 2022
@GrahamCampbell GrahamCampbell changed the title Feature/add the beforeRefreshingDatabase function to the Testing/RefreshDatabase trait [9.x] Add the beforeRefreshingDatabase function to the Testing/RefreshDatabase trait Apr 21, 2022
@roksprogar roksprogar deleted the feature/testing-before-refreshing-db branch April 22, 2022 05:11
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.

2 participants