Emily Virginita
Emily Virginita

Reputation: 161

Laravel 5.4 phpunit vs dusk tests Env App_Url

PHPunit tests and Artisan Dusk tests both use APP_URL from .env File.

But there is something strange, maybe because of my setup but I do not know, it insane.

I have Xampp, my project is on localhost/forum/

When I have

APP_URL=http://localhost

My unit tests are OK.

e.g.

$response = $this->get('sekcja/sadsadsadsadas');

        $response->assertStatus(200);

All good.

Like laravel knows it is http://localhost but tests on http://localhost/forum/ because there is this project and looks on http://localhost/forum/sekcja/sadsadsadsadas

But...

Dusk see this wrong.

Dusk is loading me localhost where is welcome XAMPP's Page. Not my project page at localhost/forum/

Then I change in ENV to APP_URL=http://localhost/forum/

And works good, dusk test are good...

But then, you know what?

My PHPunit tests aren't good, they doesn't work anymore.

They can't find this $this->get('sekcja/sadsadsadsadas'); anymore.

So my question is

What is happening here? In documentation I read for dusk i have to set this as I have set, but them my PHPunit test are broken. Why? if both phpunit and dusk test are using the same variable why they want different value for it? That's kinda silly.

Upvotes: 1

Views: 1160

Answers (1)

Ruben Beeftink
Ruben Beeftink

Reputation: 346

You can create a seperate .env file for dusk specifically.

As stated in the docs:

When running tests, Dusk will back-up your .env file and rename your Dusk environment to .env. Once the tests have completed, your .env file will be restored.

This should help you fix your problem.

https://laravel.com/docs/5.4/dusk/#environment-handling

Upvotes: 1

Related Questions