From d878021dd6ca8709fd7a0a6a3e482c8edc6469d0 Mon Sep 17 00:00:00 2001 From: Maximilian Berghoff Date: Sat, 11 Aug 2018 04:58:05 +0200 Subject: [PATCH] ensure kernel is available and booted (#186) --- src/Functional/BaseTestCase.php | 19 ++++++++++++++++++- tests/Functional/BaseTestCaseTest.php | 5 +++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Functional/BaseTestCase.php b/src/Functional/BaseTestCase.php index 7669bf0..89bce6b 100644 --- a/src/Functional/BaseTestCase.php +++ b/src/Functional/BaseTestCase.php @@ -74,7 +74,24 @@ public function getClient() */ public function getContainer() { - return self::$kernel->getContainer(); + return $this->getKernel()->getContainer(); + } + + /** + * Ensures the kernel is available. + * + * @return \Symfony\Component\HttpKernel\KernelInterface + */ + public function getKernel() + { + if (null === self::$kernel) { + self::$kernel = parent::bootKernel(); + } + if (!self::$kernel->getContainer()) { + self::$kernel->boot(); + } + + return self::$kernel; } /** diff --git a/tests/Functional/BaseTestCaseTest.php b/tests/Functional/BaseTestCaseTest.php index c547c12..c4d8fd7 100644 --- a/tests/Functional/BaseTestCaseTest.php +++ b/tests/Functional/BaseTestCaseTest.php @@ -61,6 +61,11 @@ public function testGetContainer() $this->assertEquals($this->container, $this->testCase->getContainer()); } + public function testGetKernel() + { + $this->assertInstanceOf(KernelInterface::class, $this->testCase->getKernel()); + } + public function provideTestDb() { return [