中间件测试高度依赖于中间件本身的逻辑和可能的结果。我们走吧
   
    verified
   
   您引用的中间件示例:
  
  
   如果用户未验证其电子邮件,我们希望用户被重定向(302)到“验证您的电子邮件”页面(
   
    email_verified_at
   
   属性为null),否则我们期望正常响应(200)。
  
  
   我们如何模拟用户访问我们的页面?随着
   
    actingAs
   
   方法。从
   
    docs
   
   :
  
  
   
    这个
    
     行动A
    
    助手方法提供了一种简单的方法来验证给定用户是否为当前用户。
   
  
  
   所以我们的代码看起来像这样:
  
  use App\User;
class ExampleTest extends TestCase
{
    public function testAccessWithoutVerification()
    {
        // Create a dummy user
        $user = factory(User::class)->create();
        // Try to access the page
        $response = $this->actingAs($user)
                         ->get('/the-page-we-want-to-test');
        // Assert the expected response status
        $response->assertStatus(302);
    }
    public function testAccessWithVerification()
    {
        // Create a dummy user, but this time we set the email_verified_at
        $user = factory(User::class)->create([
            'email_verified_at' => \Carbon\Carbon::now(),
        ]);
        // Try to access the page
        $response = $this->actingAs($user)
                         ->get('/the-page-we-want-to-test');
        // Assert the expected response status
        $response->assertStatus(200);
    }
}
  
   文档有一个
   
    entire page dedicated to HTTP tests
   
   ,看看。