Laravel Passport API认证测试失败?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (284)

我正在使用laravel和护照进行api认证。

当我测试包含代码登录用户的方法时,出现堆栈跟踪错误:

类节流不存在{“exception”:“[object](ReflectionException(code:-1):类节流不存在于C:\ xampp \ caramel \ vendor \ laravel \ framework \ src \ Illuminate \ Container \ 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(code:-1):Class节流不存在于C:\ xampp \ caramel \ vendor \ laravel \ framework \ src \ Illuminate \集装箱\ Container.php:752)

提问于
用户回答回答于

它可以帮助你,将这一行添加到数组中。

protected $routeMiddleware = [
....
....
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
....
];

扫码关注云+社区

领取腾讯云代金券