1
votes

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.

1
I don't know how you're running your dusk tests, are you running the standard php webserver through php artisan serve or something like that? That would be different than using XAMPP and might be the cause of your issue, i've never used XAMPP, i've only used Homestead but perhaps that is the cause of the issue.JonnySerra
I just have everything in htdocss, it is run through xampp. And i run test by php artisan dusk @JonnySerraEmily Virginita

1 Answers

1
votes

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