@pstephan1187 I suppose L4? Do you have .env.testing with APP_DOMAIN defined?
Feb 6, 2015
3
Level 7
Setting Domain in Route Test with PHPUnit
My app works on multiple domains. Depending on the domain you access the app on, different controllers are called. Here is how the routes file is setup:
Route::group(['domain' => getenv('APP_DOMAIN')], function(){
//... lots of routes
});
//Catch all
Route::any('{all}', 'SitesPublicController@index')->where('all', '.*');
So if the domain matches the APP_DOMAIN environment variable, then it is handled by controllers set in the Route Group, otherwise it is handled by the SitesPublicController index method.
Everything works just fine in the browser, but when I use PHPUnit, this test fails. It says I am getting a response of 500 instead of 200:
public function testBasicExample()
{
$response = $this->call('GET', '/');
$this->assertEquals(200, $response->getStatusCode());
}
I assume it has to do with setting the proper domain? Any ideas?
NOTE: I am using Homestead
Level 7
Doing this worked:
$response = $this->call('GET', 'http://mydomain.app/');
Farther down in the Symfony\Component\HttpFoundation\Request class was this code:
$components = parse_url($uri);
if (isset($components['host'])) {
$server['SERVER_NAME'] = $components['host'];
$server['HTTP_HOST'] = $components['host'];
}
Please or to participate in this conversation.