FrameworkBundle
FrameworkBundle provides a tight integration between Symfony components and the Symfony full-stack framework.
…Nyholm) This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [FrameworkBundle] Add KernelTestCase::getContainer() | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | yes | Tickets | | License | MIT | Doc PR | symfony/symfony-docs#14731 There are at least 3 ways to get the container in a test class: ```php class FooTest extends WebTestCase { public function testGetContainerA() { $kernel = self::bootKernel(); $container = $kernel->getContainer(); } public function testGetContainerB() { self::bootKernel(); $container = self::$container; } public function testGetContainerC() { $client = self::createClient(); $container = $client->getContainer(); } } ``` I suggest to add a fourth =) Basically, in tests you should always use the `test.service_container`. It is hard to remove A and C, but I can deprecate C and add a helper function. ```php class FooTest extends WebTestCase { public function testGetContainerTheOnlyWayYouShouldUse() { $container = $this->getContainer(); } } ``` This new way will also boot your kernel if it is not already booted. Commits ------- f4c97240ff [FrameworkBundle] Add KernelTestCase::getContainer()
FrameworkBundle provides a tight integration between Symfony components and the Symfony full-stack framework.