Home > database >  Freshly generated DuskTestCase.php throws "Undefined type 'Tests\CreatesApplication'
Freshly generated DuskTestCase.php throws "Undefined type 'Tests\CreatesApplication'

Time:04-14

I'm trying to set up Laravel Dusk to test my Laravel site as part of a larger Github Action CI/CD workflow.

Following the documentation, I ran:

composer require --dev laravel/dusk
php artisan dusk:install

The latter command created a tests/Browser directory and a tests/DuskTestCase.php file.

The problem is that when I open up DuskTestCase.php Intelephense immediately complains:

Undefined type 'Tests\CreatesApplication'

I also get a slightly different, but clearly related, error when running the GitHub Action:

PHP Fatal error:  Trait "Tests\CreatesApplication" not found in /home/runner/work/mysite/mysite/tests/DuskTestCase.php on line 10

I have the following in my composer.json:

"autoload-dev": {
    "psr-4": {
        "Tests\\": "tests/"
    }
}

...and have also run composer dump-autoload locally.

What's going on here? Why does the example test file generated by Dusk seem to ship with an error and what can I do to fix it?

CodePudding user response:

Have you deleted the CreatesApplication from your app? It comes out of the box with a fresh Laravel installation: https://github.com/laravel/laravel/blob/9.x/tests/CreatesApplication.php

Alternatively perhaps you upgraded from an earlier version of Laravel and missed the addition of this file.

  • Related