master

laravel/framework

Last updated at: 29/12/2023 09:25

ParallelTestingServiceProvider.php

TLDR

This file defines the ParallelTestingServiceProvider class, which is a service provider for parallel testing in Laravel projects.

Methods

boot

This method is called when the application's service providers are being booted. It checks if the application is running in the console and then calls the bootTestDatabase method from the TestDatabases trait.

register

This method is called when the service provider is being registered. It checks if the application is running in the console and then registers a singleton instance of the ParallelTesting class.

Classes

ParallelTestingServiceProvider

This class extends the ServiceProvider class and implements the DeferrableProvider interface. It provides the service for parallel testing in Laravel projects. It also uses the TestDatabases trait.

END

<?php

namespace Illuminate\Testing;

use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
use Illuminate\Testing\Concerns\TestDatabases;

class ParallelTestingServiceProvider extends ServiceProvider implements DeferrableProvider
{
    use TestDatabases;

    /**
     * Boot the application's service providers.
     *
     * @return void
     */
    public function boot()
    {
        if ($this->app->runningInConsole()) {
            $this->bootTestDatabase();
        }
    }

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        if ($this->app->runningInConsole()) {
            $this->app->singleton(ParallelTesting::class, function () {
                return new ParallelTesting($this->app);
            });
        }
    }
}