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

[8.x] Adds "setUpTestDatabase" support to Parallel Testing #36301

Merged
merged 1 commit into from
Feb 18, 2021

Conversation

nunomaduro
Copy link
Member

This pull request adds setUpTestDatabase support to Parallel Testing. Since we have added Parallel Testing to Laravel, some people have reported that there is no easy way to seed test databases. With this pull request, people can seed their test databases like so:

<?php

namespace App\Providers;

use Illuminate\Support\Facades\ParallelTesting;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        ParallelTesting::setUpTestDatabase(function () {
            Artisan::call('db:seed');
        });
    }
}

Of course, this hook only gets executed when the test database is created. So, if people want to re-seed their test databases they will need to call art test --parallel --recreate-databases.

@introwit @daniloesser @johanvanhelden Please let me know what do you think.

@nunomaduro
Copy link
Member Author

Please keep in mind that using something like Artisan::call('db:seed'); only makes sense if you are using DatabaseTransactions in your entire test suite.

@BertvanHoekelen
Copy link
Contributor

Thank you @nunomaduro!

@nunomaduro
Copy link
Member Author

@BertvanHoekelen Can you pull this branch locally and give this a try?

@BertvanHoekelen
Copy link
Contributor

@nunomaduro Just tried. Works like a charm! First time database gets seeded second time it skips the seeding. Awesome!
When this gets merged I can finally ditch my custom seed migration :)

@johanvanhelden
Copy link
Contributor

@nunomaduro I pulled the branch and can also confirm it is working flawlessly for my custom bootstrapper! Thank you so much Nuno!

@daniloesser
Copy link

@nunomaduro , I can also confirm that the feature is working well! Thank you very much for this improvement!

@nunomaduro nunomaduro marked this pull request as ready for review February 17, 2021 23:07
@taylorotwell taylorotwell merged commit aeb0bf5 into 8.x Feb 18, 2021
@taylorotwell taylorotwell deleted the feat/set-up-test-database branch February 18, 2021 15:11
@taylorotwell
Copy link
Member

@nunomaduro could you submit a documentation PR for this? Thanks!

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.

None yet

5 participants