Skip to content

Cannot get the Security service in the tests #31647

@mnapoli

Description

@mnapoli

Symfony version(s) affected: 4.2.4

Description

class AuthorizationTest extends WebTestCase
{
    public function testXxx(): void
    {
        self::bootKernel();
        $security = self::$container->get(Security::class);
        // ...
    }
}

Throws:

ServiceNotFoundException : The "Symfony\Component\Security\Core\Security" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

The self::$container is the test container, it should let us access private services.

Am I missing something?

How to reproduce

class AuthorizationTest extends WebTestCase
{
    public function testXxx(): void
    {
        self::bootKernel();
        self::$container->get(Security::class);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions