Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection][4.0] Defining a private synthetic service shouldn't be possible #25253

Copy link
Copy link
Closed
@Jean85

Description

@Jean85
Issue body actions
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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.