【发布时间】:2020-04-05 19:34:06
【问题描述】:
我有一个新的中间件,可以在浏览器中按预期工作。但是,当我尝试通过功能测试触发中间件时,永远不会调用 handle()。
我知道我可以为这个中间件编写一个单元测试,并且应该这样做。但是我的实际功能测试是否应该转移到浏览器测试中?
# Kernel.php
protected $middlewareGroups = [
'web' => [
MyMiddleware::class,
...
# MyMiddleware.php
public function handle($request, Closure $next)
{
dd('I can see this in the browser, but not in the Feature test. Doing some 302 magic here.');
# Feature Test
/**
* @test
* @return void
*/
public function my_new_test(): void
{
$this->get('/test')
->assertStatus(302)
->assertRedirect($vanityDomain->getFallbackRedirectUrl('/non-matching-path'));
}
【问题讨论】: