Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TestContainer should not be @internal #46483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ddeboer opened this issue May 28, 2022 · 3 comments
Closed

TestContainer should not be @internal #46483

ddeboer opened this issue May 28, 2022 · 3 comments

Comments

@ddeboer
Copy link
Contributor

ddeboer commented May 28, 2022

Symfony version(s) affected

6.1.0

Description

#44695 added @return TestContainer to KernelTestCase::getContainer(). However, TestContainer is marked @internal, which makes any calls static::getContainer()->get(MyService::class) invalid, for example to Psalm (and possibly also to IDEs):

ERROR: InternalMethod - MyTest.php:16:49 - The method Symfony\Bundle\FrameworkBundle\Test\TestContainer::get is internal to Symfony but called from MyTest (see https://psalm.dev/175)
        $this->client = static::getContainer()->get(MyService::class);

How to reproduce

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

final class MyTest extends KernelTestCase
{
    public function test_container_get(): void
    {
        static::getContainer()->get(MyService::class);
    }
}

Possible Solution

Remove @internal from TestContainer.

Additional Context

No response

@wouterj
Copy link
Member

wouterj commented May 28, 2022

For reference, this was also discussed shortly on Symfony Slack yesterday:

tarlepp 2:39 PM
hmm, after update to Symfony 6.1.0 I'm seeing quite lot errors like:

psalm: InternalMethod: The method Symfony\Bundle\FrameworkBundle\Test\TestContainer::get is internal to Symfony but called from ...

that TestContainer is marked as @internal any ideas how to fix this?

wouterj 2:55 PM
I feel like @internal is a mistake there, it should be @Final at most
2:55
But it has been there since 4 years, interesting that this comes up now

stof 2:57 PM
maybe it has been added in a return type somewhere in 6.1
2:58
btw, maybe having it as internal is actually the good thing, but the return type should be the ContainerInterface rather than the internal implementation

tarlepp 3:01 PM
yep, that getContainer method has

@return TestContainer

annotation if that is removed there aren't those errors anymore

@xabbuh
Copy link
Member

xabbuh commented May 29, 2022

Can you confirm that the change I propose in #46496 works as well for you?

@ddeboer
Copy link
Contributor Author

ddeboer commented May 30, 2022

@xabbuh Confirmed!

nicolas-grekas added a commit that referenced this issue May 30, 2022
…rnal class (xabbuh)

This PR was merged into the 6.1 branch.

Discussion
----------

[FrameworkBundle] update docblock to not expose the internal class

| Q             | A
| ------------- | ---
| Branch?       | 6.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #46483
| License       | MIT
| Doc PR        |

The change was introduced in #44695 motivated by the idea to be able to use the `getServiceIds()` and `getRemovedIds()` methods which are Symfony-specific methods. Exposing the `TestContainer` has the drawback of static analysis tools complaining about making use of internal classes. Since the interesting methods are part of the base `Container` class which is not internal I propose to change the docblock to return an instance of this class instead.

Commits
-------

f30db82 update docblock to not expose the internal class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants