A colleage changed the code of my service to use the isGranted method of of the AuthorizationCheckerInterface to check the rights. Like this:
$this->authorizationChecker->isGranted(Roles::ROLE_PERSON_VIEW);
Regretfully, he didn't adapt my phpunit tests so I am left with changing my tests so they pass again.
The service I am testing is created like this in my test:
protected function getService(string $id): ?object
{
$kernel = static::createKernel();
$kernel->boot();
return $kernel
->getContainer()
->get($id);
}
/** @var AuthorizationCheckerInterface $authorizationChecker */
$authorizationChecker = $this->getService('AuthorizationChecker');
$this->manager = new Manager(
$entityManager,
$fooService,
$baaService,
$authorizationChecker
);
Which results in the error:
ServiceNotFoundException: You have requested a non-existent service "AuthorizationChecker"
I first tried mocking the service, but without defining the result I got "null" and defining the result makes it quite useless for my tests, because I mock the user right already and want to test if they play together correctly with the rest of my code, so it is a kind of functional test, rather than a unit test.
If I create the AuthorizationChecker manually I have the same problem with the TokenStorageInterface and the AccessDecisionManagerInterface.
What is the best way to test my code?