我正在使用laravel和护照进行api身份验证。
当我测试包含登录用户的代码的方法时,我得到一个堆栈跟踪错误:
类别限制不存在{“exception”:“[object] (ReflectionException(代码:-1):类别限制不存在于 C:\ XAMPP \焦糖\厂商\ laravel \框架\ SRC \照亮\容器\ Container.php:752)
登录用户功能
private function loginUser($user, $password)
{
$client = DB::table('oauth_clients')->where('id', 2)->first();
//form parameters to get access token
$params = [
'client_id' =>$client->id,
'client_secret' => $client->secret,
'grant_type' => 'password',
'username' => $user->email,
'password' => $password,
'scope' => '*'
];
$request = Request::create('oauth/token', 'POST',$params);
$response = json_decode(Route::dispatch($request)->getContent());
$data = array();
if($response->access_token != null)
{
$data['response'] = config('app.success');
}
else
{
$data['response'] = config('app.failed');
}
$data['user'] = $user;
$data['token'] = $response;
return $data;
}
测试功能
public function testLoginUser()
{
$user = User::find(1);
$class = App::make('App\Http\Controllers\v1\Auth\api\PassportLogin');
$methodName = 'loginUser';
$method = $this->privateMethod($class,$methodName);;
$data = $method->invokeArgs($class,array($user,'caramel'));
$this->assertNotNull($data);
}
堆栈跟踪
testing.ERROR:类别限制不存在{“exception”:“[object] (ReflectionException(代码:-1):类别限制不存在于 C:\ XAMPP \焦糖\厂商\ laravel \框架\ SRC \照亮\容器\ Container.php:752)
答案 0 :(得分:1)
它可以帮助你,将这一行添加到数组。
protected $routeMiddleware = [
....
....
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
....
];