-
Notifications
You must be signed in to change notification settings - Fork 96
Followup of Symfony TestContainer issue #212
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
Conversation
Please fix the build failures.
Done!
yakobe
commented
Dec 5, 2021
@Pierstoval This works perfectly for me too 👍 !
@ondrejmirtes Would it be possible to get this in? Or is there a release schedule to wait for?
Thanks for all the hard work everyone 😊.
Thank you! Gonna release it immediately.
This seems to end in a strange error now when using a trait expecting a getContainer
method with ContainerInterface
as return type to exist:
I'm now getting:
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Line src/Sulu/Bundle/TestBundle/Testing/ContainerTrait.php (in context of class Sulu\Bundle\TestBundle\Testing\KernelTestCase) ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 32 Method Sulu\Bundle\TestBundle\Testing\KernelTestCase::getContainer() should return Symfony\Bundle\FrameworkBundle\Test\TestContainer but returns Symfony\Component\DependencyInjection\ContainerInterface. ------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I'm not understanding why here Symfony\Bundle\FrameworkBundle\Test\TestContainer
is expected.
I think the Problem is that phpstan is not knowing that TestContainer
is an instance of Symfony\Component\DependencyInjection\ContainerInterface
now? But I could not find it how to achieve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also think this should be protected static
like the implemntation: https://github.com/symfony/symfony/blob/94533d419fb54aac8c9391fa9cbe03342ee8f374/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php#L88
I'm meeting the same issue as @alexander-schranz, why KernelTestCase::getContainer
is marked to return TestContainer? There is no such thing guarranteed in the implementation, is it?
Indeed there's no real guarantee based on types, but in practice, it's always the case when using the full-stack framework: https://github.com/symfony/symfony/blob/60ce5a3dfbd90fad60cd39fcb3d7bf7888a48659/src/Symfony/Bundle/FrameworkBundle/Resources/config/test.php#L48
Think Symfony\Bundle\FrameworkBundle\Test\TestContainer
is correct and nobody would overwrite that. But think the main problem is that PHPStan does not now that Symfony\Bundle\FrameworkBundle\Test\TestContainer
is implementing Symfony\Component\DependencyInjection\ContainerInterface
. Because if it would I think the error would be gone.
The stubs
implementation looks for me currently not allowing to achieve this, and also think that the stubs
are not very future proof as when typehints change in different symfony versions. Maybe there is another workaround to tell that KernelTestCase
return a TestContainer
without adding stubs here, so PHPStan also knows which interfaces TestContainer implements and also would implement in the future. /cc @ondrejmirtes do you see other ways to achieve the same result?
Maybe a more general solution to provide access to test container xml and dev container xml and based what files are analyzed the correct services are returned so also other services which are available only in test environment work like expected:
container_xml_path: var/cache/dev/srcDevDebugProjectContainer.xml test_container_xml_path: var/cache/test/srcTestDebugProjectContainer.xml test_file_regex: 'Test.php$'
Or we can manipulate the loading of srcDevDebugProjectContainer
that test.service_container
points to TestContainer.
test.service_container
should already contain an instance of TestContainer
.
About the XML part, I'm not sure about what you'd like to achieve. I personally specify the Test container in my container_xml_path
and it doesn't detect the TestContainer
either, unless using the stubs in phpstan 😕
Followup of #27 and #210