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

Cannot get the Security service in the tests #31647

Copy link
Copy link
Closed
@mnapoli

Description

@mnapoli
Issue body actions

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

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