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

[FrameworkBundle] RFC: Make Symfony\Bundle\FrameworkBundle\Test\TestContainer non-internal and change the return type of KernelTestCase::getContainer #61950

Copy link
Copy link
@Crovitche-1623

Description

@Crovitche-1623
Issue body actions

Description

Actually, PHPStan throws errors because it cannot resolve the correct type from following code:

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\Container;

class FooTest extends KernelTestCase {
    private Container $container;

    protected function setUp(): void
    {
        $this->container = self::getContainer();
    }

    public function testBar() {
        $serializer = $this->container->get('serializer');

        // ...
    }
}

The previous code with fail with PHPStan errors like (Service "serializer" is private.).

After digging up in the getContainer method, I saw that the returned container was TestContainer and not a Container as indicated in the return type.

If I change the code to this:

// ...
use Symfony\Bundle\FrameworkBundle\Test\TestContainer;

class FooTest extends KernelTestCase {
    private TestContainer $container;

    // ...
}

The errors are gone but I do have other warnings (not from PHPStan though) indicating that the TestContainer is marked as internal.

WDYT about removing the @internal phpdoc annotation and specifying a better typehint @nicolas-grekas ?

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrameworkBundleRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)

    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.