Description
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | yes |
RFC? | no |
Symfony version | 4.0 |
[UPDATE] I was attempting to do something that shouldn't have worked.
This stems from facile-it/paraunit#112 too, as #25242.
I was following the suggestion from @nicolas-grekas to use public aliases to access private services during tests, but I've found an issue with private synthetic services.
Basically, if you have a private synthetic service that you want to access during a test, you have to do these 4 operations:
- add synthetic service definition as private
- add public alias
- compile
- set the synthetic service
...and the retrieve the service through the alias.
With 3.4 and that order of operations, it works.
With 4.0, it doesn't work, even with different orders. Basically I can move around just the command that sets the synthetic service, but:
- setting the synthetic service as the first operation makes the service unreachable by the consequent alias definition:
InvalidArgumentException: Unable to replace alias "public_alias" with actual definition "[...]".
/home/user/project/vendor/symfony/dependency-injection/Compiler/ReplaceAliasByActualDefinitionPass.php:57
[...]
Caused by
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "[...]"
- setting the synthetic service erases any linked alias, so it must be done after the compilation, or the alias must be defined after;
- the alias must be defined before the compilation, or the service gets inlined since it's private
Am I missing something else?