Skip to content

[PhpUnitBridge] Don't show deprecation warnings when getting private services from test client container #27037

Closed
@arderyp

Description

@arderyp
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? ?
Symfony version 4.1.x

Related

The issues above demonstrate the newly committed functionality whereby we can freely access private services from the test client in phpunit test classes. Based on those issues, and the current documentation on symfony.com, I have come up with the following code, which works for my purposes:

class MyWebTestCase extends WebTestCase
{
    public function setUp()
    {
        parent::setUp();
        $this->client = static::createClient();
        $this->client->disableReboot();
        $this->container = $this->client->getContainer();
    }

    public function testSomething()
    {
        ....
        $this->container->get(MyCustomService::class);  // WARNING: MyCustomService service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0
        ....
    }
}

class MyCustomConsoleCommandTestCase extends WebTestCase
{
    public function setUp()
    {
        parent::setUp();
        $this->application = new Application(self::bootKernel());
        $this->client = static::createClient();
        $this->container = $this->client->getContainer();
    }

    public function testSomething()
    {
        ....
        $this->container->get(MyCustomService::class);  // WARNING: MyCustomService service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0
        ....
    }
}

While the code works, the calls to the test client container's get() method produce the familiar service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0 deprecation warning. If my approach to accessing the test container is incorrect, please let me know. Otherwise, shouldn't PhpUnitBridge not throw said deprecation warning in these testing contexts?

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