I'm a noob in unit testing and I want to test my API. So, LexikJWTAuthenticationBundle works fine when I try to access in /login_check path and the CRUL command line. But when I try to do the TestCase I get this error :
1) Tests\AppBundle\Controller\StoreControllerTest::testPOSTRate GuzzleHttp\Exception\ClientException: Client error: GET http://localhost:8000/api/stores resulted in a 401 Unauthorized response: {"code":401,"message":"Invalid JWT Token"}
My testPOST function :
public function testPOSTRate(){
$data = array(
'rate' => 1,
'store' => 1
);
// I'm not sure if it's the right way to get Token
$token = $this->getService('lexik_jwt_authentication.encoder')->encode([
'username' => 'Nacer',
]);
$this->client->get('http://localhost:8000/api/stores', [
'body' => json_encode($data),
'headers' => [
'Authorization' => 'Bearer '.$token
]
]);
}