Skip to content

Navigation Menu

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

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

Copy link
Copy link
Closed
@arderyp

Description

@arderyp
Issue body actions
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

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