Level 51
I tried that and was not able to mock Request class. May be this will work: https://stackoverflow.com/a/43681275
\URL::forceRootUrl('https://' . $client->domain);
Summer Sale! All accounts are 50% off this week.
I have an app where different domains can access my api, and I have created the following middleware to detect this:
class ValidateClient
{
public function handle(Request $request, Closure $next)
{
$client = Client::where('domain', $request->getHost())->first();
if ($client) {
Config::set('client', $client->toArray());
}
return $next($request);
}
}
How can I write a test that mocks a domain so I can test my middleware?
I have tried the following in my test but this doesn't seem to work:
$client = Client::factory()->create();
$request = \Mockery::mock(Request::class, ['getHost' => $client->domain]);
$this->app->instance(Request::class, $request);
$response = $this->get(route('report.index'));
dd($response->getContent());
But if I dump the request data
dd($request->getHost());
in my middleware I just get
localhost
Any help would be much appreciated...
Please or to participate in this conversation.