-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] TestContainer @internal annotation conflicts with official testing usage #60299
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
Comments
Sorry I cannot check on my own: where does Symfony expose this class as an "api" type? |
probably here
|
Thanks. |
The same happens with Polyfills, for example using
Even when the intl extension is installed and the polyfill is unused. |
Let me close since there's nothing to fix on this side: the code declares things the way it should. |
PHPStan has to typehint Some references:
I'm not using this part of Symfony so I can't judge who's right or wrong here. Anyone care to elaborate? |
I get that. I don't know how to solve this issue. To me this looks like something phpstan/SA tools needs to deal with somehow. If Symfony can help, sure, but making TestContainer non-internal doesn't seem appropriate to me here. It's just a class with some implementation in it. Making it a fully supported type would increase the surface of the BC promise for no good reasons. The fact this concretion is used to give access to private services is just an implementation detail from the PoV of Symfony. |
@nicolas-grekas I agree with you. We need to mark the container fetched via this method somehow. Or we can allow fetching private services on all ContainerInterface when we're in KernelTestCase subclass. |
@ondrejmirtes I annotated TestContainer.stub with |
@mickverm PHPStan doesn't interpret The problem with removing The right solution is to remove these stubs altogether:
And fix this line https://github.com/phpstan/phpstan-symfony/blob/cf8c9c6994cf2a07c7aefddef2b26941d19efba1/src/Rules/Symfony/ContainerInterfacePrivateServiceRule.php#L46 with some other condition. |
Solved in phpstan-symfony 2.0.6 thanks to phpstan/phpstan-symfony#441. |
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
5.x, 6.x, 7.x
Description
When using PHPStan 2.1.13 with bleeding edge enabled, calls to
TestContainer::get()
andTestContainer::set()
as used in the official Symfony testing documentation (https://symfony.com/doc/current/testing.html#integration-tests) trigger the following errors:These methods are essential for setting up integration tests as per Symfony's own recommendations. However, PHPStan is flagging them due to the
@internal
annotation on theTestContainer
class.How to reproduce
See: phpstan/phpstan#12941
Possible Solution
Either:
@internal
annotation onTestContainer
, or@api
or similar visibility annotations to theget()
andset()
methods to clarify their intended use in test environments.Additional Context
No response
The text was updated successfully, but these errors were encountered: