1

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)

1

1 Answer 1

1

might it can help you , adding this line to array.

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

];

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.