I've changed the app.url config value to the correct url (http://testing.local
) for testing locally, however when I run my phpunit tests and try to call(), it is trying to query http://localhost
instead of the value of app.url. What do I need to do to get phpunit to call the right path?
I know that it is not actually calling the url, just processing it as if it was, but I can't seem to get it to actually work. Could it have something to do with testing.local directly linking to /public
instead of /
?
To change testing url of PHPUnit:
Go to /tests/TestCase.php
in your Laravel project.
Change next line to url you need:
// The base URL to use while testing the application.
protected $baseUrl = 'http://newurl.com';
Done.
If you want to statically specify a root URL for your tests, add this to phpunit.xml:
<env name="APP_URL" value="http://testing.local"/>
Instead, if you want to change the URL dinamically during your tests, from Laravel 5.4 the $baseUrl
method doesn't work anymore.
Also, trying to set the url dinamically with \Config:set('app.url', 'http://testing.local')
doesn't work either, as it seems that Laravel caches the root url
You can set dynamically a custom URL with:
\URL::forceRootUrl('http://testing.local');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With