expectException(AuthorizationException::class); /** * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable */ $user = User::factory()->create(); $this->actingAs($user); $request = Request::create('/admin', 'GET'); $middleware = new AdminOnly; $response = $middleware->handle($request, function () { }); } /** * @test */ public function test_admins_pass() { /** * @var \App\Models\User|\Illuminate\Contracts\Auth\Authenticatable */ $admin = User::factory()->administrator()->create(); $this->actingAs($admin); $request = Request::create('/admin', 'GET'); $middleware = new AdminOnly; $response = $middleware->handle($request, function () { }); $this->assertNull($response); } }