我试图在我的Laravel应用中测试Google登录。
当我尝试访问Google登录页面时,我会收到404。
我的想法是,在TestCase.php中,我有一个变量:
protected $baseUrl = 'http://laravel.dev';
所以,它可能会发生冲突......好吧,我不知道该怎么做,或者解决它!
这是我的代码:
$this->visit('/auth/login')
->click('google');
dump(Request::url()); // https://accounts.google.com/o/oauth2/auth
$this->dump(); --> Gives me a 404 page
欢迎任何想法!
答案 0 :(得分:0)
答案是否定的。该框架不支持它。如果你稍微挖一下,当你用"访问"进行测试时,你会发现,请求实际上并没有发出。在类MakesHttpRequests的调用方法中,它初始化一个laravel http内核并通过它放置请求。实际上没有发出http请求。
$kernel = $this->app->make('Illuminate\Contracts\Http\Kernel');
$this->currentUri = $this->prepareUrlForRequest($uri);
$this->resetPageContext();
$request = Request::create(
$this->currentUri, $method, $parameters,
$cookies, $files, array_replace($this->serverVariables, $server), $content
);
$response = $kernel->handle($request);
你可以尝试的唯一方法是模仿这部分。