I have created a custom token authentication class by extending the AbstractGuardAuthenticator class as explained here. My requirement was to accept a jwt, extract it and identify the user by check it's id against the database which is working completely fine.
Now I need to override underlying methods of it to use in php unit tests. In simple words, bypass it and set a default user. So I can test API end points without passing user tokens everytime when I do a functional test.
What I tried
I tried to defined a separate security.yaml in test folder and call customized class using it to override but still app calls the default class.
Path: config/packages/test/security.yaml
security:
firewalls:
main:
anonymous: lazy
logout: ~
guard:
authenticators:
- Otrium\Infrastructure\Security\TestTokenAuthenticator
entry_point: Otrium\Infrastructure\Security\TestTokenAuthenticator
stateless: true
The only solution I found so far is to keep a matching jwt and pass it as a header value on each test.
Symfony version - 5 / Php version - 7.4