Laravel phpunit does not get the correct URL

I changed the app.url configuration value to the correct url ( http://testing.local) for testing locally, however, when I run my phpunit tests and try to call (), it tries to request the http://localhostvalue of app.url instead. What do I need to do to get phpunit to call the correct path?

I know that it doesn’t actually invoke the URL, just treating it as if it were, but I cannot get it to work. Could this have anything to do with test.local directly related to /publicinstead /?

+4
source share
3 answers

Change PHPUnit Test URL:

Go to /tests/TestCase.phpthe Laravel project.

Change the following line for the url you need:

// The base URL to use while testing the application.
protected $baseUrl = 'http://newurl.com';

Done.

+5
source

If you want to statically specify the root URL for your tests, add it to phpunit.xml:

<env name="APP_URL" value="http://testing.local"/>

Instead, if you want to change the URL dynamically during tests, from Laravel 5.4 the method $baseUrlno longer works

Also, trying to set the URL dynamically using \Config:set('app.url', 'http://testing.local')doesn't work either, as it seems like Laravel is caching the root URL

A dynamically configurable URL can be configured using:

\URL::forceRootUrl('http://testing.local');
+1
source

, Laravel , PHPUnit. . , URL- .

$test_url = Config::get('app.url');

, , .

0

Source: https://habr.com/ru/post/1535768/


All Articles