Skip to content

Document how to "integration" test private services #8097

Closed
@weaverryan

Description

@weaverryan

Question:

What if you do container->get() some services in tests.

Answer:

The proper solution would be to create a public alias for the service you want to test in the test environment only:

# app/config/config_test.yml
services:
    test_alias.AppBundle\Service\MyService:
        alias: 'AppBundle\Service\MyService'
        public: true # require on SF4, where everything is private by default

Then, you would actually fetch test_alias.AppBundle\Service\MyService out of the container in your unit test. It's a nice idea too: you only need to expose your service as public in the test environment.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions