create(['username' => 'admin']); $this->actingAs($user, 'admin'); $auth = auth('admin'); $this->user = $user; $this->token = $auth->tokenById($user->id); $auth->setToken($this->token); } protected function setUp(): void { parent::setUp(); $this->checkPermission(false); $this->storage = Storage::disk($this->filesystem); } /** * 设置是否需要检测权限 * * @param bool $check */ protected function checkPermission($check) { if ($check) { $ins = new class extends AdminPermission { protected $urlWhitelist = [ '/test-resources/pass-through', ]; }; } else { $ins = new class extends AdminPermission { public function handle(Request $request, \Closure $next, ...$args) { return $next($request); } }; } $this->app->singleton(PermissionMiddleware::class, function () use ($ins) { return $ins; }); } }