我正在使用带有passport的laravel进行api身份验证。
当我测试包含用户登录代码的方法时,我得到一个stacktrace错误:
异常类限制不存在{“
”:“object
登录用户函数
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);
}
堆栈跟踪
{"exception":"object
testing.ERROR:类限制不存在
https://stackoverflow.com/questions/48702739
复制相似问题