Dwight Watson's blog

Changing the base URI with Laravel 5.4 testing

This blog post was originally published a little while ago. Please consider that it may no longer be relevant or even accurate.

While upgrading my app from to Laravel 5.4 and replacing my "BrowserKit" style tests with the new evolution TestCase I ran into some trouble testing routes that came through on subdomains. The tests that used to pass would now 404. Previously, I used this at the top of a test case to set the base URL (my API endpoint) so that the tests would run off it.

/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://api.dwightwatson.com';

However it seems Laravel 5.4 doesn't look for a baseUrl property and instead relies on the app.url configuration. Luckily, this is easy to change out on the fly in your tests, even in the setUp method.

function setUp()
{
parent::setUp();

config(['app.url' => 'http://api.studentvip.com.au']);
}

A blog about Laravel & Rails by Dwight Watson;

Picture of Dwight Watson

Follow me on Twitter, or GitHub.