2

I'm trying to run Laravel Dusk and I need to use a test database. When I check the screenshot it says that the database doesn't exist. Problem is that is the database defined on .env and not the one on .env.dusk ... I've tried to rename the file to .env.dusk.local and still no luck. What am I doing wrong?

Bruno Teixeira
  • 565
  • 4
  • 11
  • 25
  • What was the answer? This has driven me crazy for a long time. When I run `php artisan dusk`, it ignores my `.env.dusk.local`, which I can prove by inserting `dd(env('APP_ENV'));` into DuskCommand.php. – Ryan Jul 07 '18 at 13:11

4 Answers4

0

Try clearing your cache? I remember having similar issues when I first started using dusk.

php artisan cache:clear
0

I got the same problem. Lately I figured out that the .env file is being cached before dusk start.

I resolved it by adding

$this->artisan('config:cache');

into the createApplication() function in CreateApplication.php. It works :)

But then, if I finished the dusk test, I must run

php artisan config:cache

to get the original server running.

Edit:

later I tried simply call the

php artisan config:clear

also prevent the application caching the env variable. (Much simpler and faster)

0

I was able to get this to work by following these steps:

  1. Remove .env.testing
  2. Run php artisan dusk (This will create phpunit.dusk.xml).
  3. Add the following to the end of this newly created file
<phpunit>
    ...

    <php>
        <server name="APP_ENV" value="local"/>
    </php>
</phpunit>
  1. You can now restore .env.testing which can still be used for phpunit testing.

ORIGINAL ANSWER

I found that if you remove .env.testing it then uses .env.dusk.local. It seems that .env.testing always take precedence.

This does not solve the problem of using a separate .env for unit tests & dusk; which is useful when running unit tests in memory and dusk tests using sqlite.

Precastic
  • 3,742
  • 1
  • 24
  • 29
  • Not sure whether it's just my environment, but `phpunit.dusk.xml` is deleted immediately after `dusk` exits so it's not possible to save anything to it. It's entirely possible however that this is just another in a long line of bugs and generally abysmal issues that Laravel Dusk seems to ship with. – Hashim Aziz Apr 14 '22 at 22:37
0

Same issue... The problem is you forgot to create config cache file for your testing env so dusk will use your current local config cache file instead. Here is the fix:

1/ duplicate .env to .env.dusk.testing and edit the following:

APP_ENV=testing

DB_DATABASE=halfwish_test #I use different MYSQL database for testing.

2/ run this cmd:

$ php artisan config:cache --env=dusk.testing && php artisan clear //clear compiled services and packages files and cache config file.
$ php artisan migrate:fresh --env=dusk.testing && php artisan seed --env=dusk.testing //this is migrating and seeding demo data to DB.

Now you can run php artisan dusk.

free2idol1
  • 174
  • 1
  • 3
  • 12