我正在尝试在我的 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
欢迎任何想法!
最佳答案
答案是否定的。该框架不支持它。如果你稍微挖掘一下,你会发现当你用“访问”进行测试时,请求实际上并没有发出。在类 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);
您可以尝试的唯一方法是模拟这部分。
关于php - 使用外部 URL 在 Laravel 中进行功能测试(谷歌登录),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36189501/