Reputation: 95
I'm using laravel with passport for api authentication.
When I test my method which contains code to login the user, I get a stacktrace error:
Class throttle does not exist {"exception":"[object] (ReflectionException(code: -1): Class throttle does not exist at C:\xampp\caramel\vendor\laravel\framework\src\Illuminate\Container\Container.php:752)
Login User Function
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;
}
Test Function
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);
}
Stacktrace
testing.ERROR: Class throttle does not exist {"exception":"[object] (ReflectionException(code: -1): Class throttle does not exist at C:\xampp\caramel\vendor\laravel\framework\src\Illuminate\Container\Container.php:752)
Upvotes: 1
Views: 810
Reputation: 247
might it can help you , adding this line to array.
protected $routeMiddleware = [
....
....
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
....
];
Upvotes: 1