1

I have Postman API requests (POST request) containing grant_type = 'password', username = 'abc', password='xyz'. By passing this I get an token = 'xxx' and token_type = 'Bearer'. How do I write an phpunit test in laravel for such api requests?

1 Answer 1

1

you can make a test by php artisan make test:PassportTest.

Then you can use

$response = $this->json('POST','/api/token',['grant_type'=>'password','username'='abc','password'=>'xyz']);
$response-> assertJsonStructure([
    'token'=>'xxx',
    'token_type'=>'Bearer'
]);

You can also use $response->assertDatabaseHas($tokenTable,$data) to check if there is a record in you databse;

Cant see your database structures,so you need a little change to suit your own project.

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.