Search code examples
laravellaravel-5laravel-dusk

Is createApplication() method required for Laravel Dusk test cases?


I am attempting to set up Laravel Dusk in a Laravel 5.4 application. Executing php artisan dusk does not launch a browser window as shown in this guide and I am trying to figure out why. PHPStorm complains that the ExampleTest class created during execution of the php artisan dusk:install command must implement the createApplication() method, but I cannot find any mention of this method in:

  1. The official Laravel guide
  2. This Scotch.io guide
  3. A search of all files within the Laravel application directory using PHPStorm's search function.

ExampleTest class is as follows:

class ExampleTest extends DuskTestCase
{
    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->browse(function ($browser) {
            $browser->visit('/')
                    ->assertSee('Laravel');
        });
    }
}

Solution

  • Yes, this is required.

    One method to solve this is to simply add the code contained in the trait (from a later version of Laravel) to your DuskTestCase.

    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';
    
        $app->make(Kernel::class)->bootstrap();
    
        return $app;
    }
    

    Alternatively, you can create the CreatesApplication trait, paste the above code within in, and use CreatesApplication within your DuskTestCase.