镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

cantSeeAuthentication()/dontSeeAuthentication() does not work due to missing service #138

Closed

Description

@W0rma

I'm using symfony 5.3 and the new authenticator-based security (https://symfony.com/doc/current/security/authenticator_manager.html)

Calling cantSeeAuthentication()/dontSeeAuthentication() fails with the error message

Service security.helper is not available in container.
If the service isn't injected anywhere in your app, you need to set it to `public` in your `config/services_test.php`/`.yaml`,
see https://symfony.com/doc/current/testing.html#accessing-the-container

From what I can see the service security.helper is grabbed directly from the container here: https://github.com/Codeception/module-symfony/blob/main/src/Codeception/Module/Symfony/SecurityAssertionsTrait.php#L180

Can anybody confirm this issue?

Activity

  1. TavoNiievez commented on Jun 16, 2021

    @TavoNiievez
    Member

    We have a test project (codeception/symfony-module-tests) that has tests with this module.

    I updated this project to Symfony 5.3 using the new security system and according to our tests both methods are working correctly.

    If the service isn't injected anywhere in your app, you need to set it to public in your config/services_test.php/.yaml

    The error message gives you a little clue as to what the problem may be.

    In the case of our test project, we do not have the security service defined as public in a test configuration file services_test. *, In our case, that service is injected into our SecurityAuthenticator class of the new Symfony security system, although actually that service is not used anywhere in that class.

  2. W0rma commented on Jun 17, 2021

    @W0rma
    ContributorAuthor

    Thank you for the quick reply.

    So a workaround would be to inject the service security.helper somewhere in my app in order to avoid being removed during compilation of the DI container.

    I wonder if there is a way to ensure that the service is always available when using the symfony module.

  3. TavoNiievez commented on Sep 2, 2021

    @TavoNiievez
    Member

    I just made the changes in symfony-module-tests:

    https://github.com/Codeception/symfony-module-tests/pull/19/files

    Instead of doing a ghost injection of the security service in the app I defined the alias 'security.helper' as public in the test environment thanks to the services_test.php/.yaml file.

    I wonder if there is a way to ensure that the service is always available when using the symfony module.

    Regarding this question... I think that, even if there is a way to define that specific service as public in the test environment programmatically we probably should not do it, since each user should be able to decide exactly which services are public in their tests and which not.

    Fail Service security.helper is not available in container.
                If the service isn't injected anywhere in your app, you need to set it to `public` in your `config/services_test.php`/`.yaml`,
                see https://symfony.com/doc/current/testing.html#accessing-the-container
    

    So the solution is to improve the error message a bit more so that each user can define the alias for that service himself.

    I'll close this issue when I have the PR by modifying that documentation.

  4. TavoNiievez commented on Oct 7, 2021

    @TavoNiievez
    Member

    PR #142, #144 and #145 add the documentation that was required to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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