symfonyphpunitapi-platform.comlexikjwtauthbundle

Symfony API Platform : "Unable to create a signed JWT from the given configuration." during tests


I made a test login function in a test file for authentication that extends ApiTestCase:

class AuthenticationTest extends ApiTestCase {
public function testLogin(): void
{
    $client = self::createClient();
    $container = self::getContainer();

    $user = new User('username', [ 'ROLE_USER' ], 'e1420fb9-af64-4fb8-3c25-a0449b15fe7a');
    $user->setPassword(
        $container->get('security.user_password_hasher')->hashPassword($user, 'T3ST')
    );
    dump($user);

    $manager = $container->get('doctrine')->getManager();
    $manager->persist($user);
    $manager->flush();

    $response = $client->request('POST', '/api/login', [
        'headers' => ['Content-Type' => 'application/json'],
        'json' => [
            "username" => "username",
            "password" => "T3ST"
    ]]);

    $this->assertResponseIsSuccessful();
}
}

When I run phpunit tests I got this error : "Unable to create a signed JWT from the given configuration." Calling this login route externally (curl, swagger) works and I have a JWT token in the response.

Does anyone have a solution?


Solution

  • I found the probleme. I had not configured my .env.test file as my local .env file. 🙃