From 426126192a94e847f0e21957d63e7edc3dad496e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Poirier=20Th=C3=A9or=C3=AAt?= Date: Tue, 21 May 2024 16:00:53 -0400 Subject: [PATCH] Ensure kernel is shutdown before createClient is called --- .../Extension/SetUpAutowire/SetUpAutowireExtension.php | 7 +++++++ tests/Controller/Security/TwoFactorAuthorizationTest.php | 5 ----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/tester-bundle/PHPUnit/Extension/SetUpAutowire/SetUpAutowireExtension.php b/packages/tester-bundle/PHPUnit/Extension/SetUpAutowire/SetUpAutowireExtension.php index 29e0a82d..f71f1c21 100644 --- a/packages/tester-bundle/PHPUnit/Extension/SetUpAutowire/SetUpAutowireExtension.php +++ b/packages/tester-bundle/PHPUnit/Extension/SetUpAutowire/SetUpAutowireExtension.php @@ -118,6 +118,13 @@ private function initializeClients(TestCase $testCase): void ); } + // This is to ensure the kernel is not booted before calling createClient + // Can happen if we use the container in a setUpBeforeClass method or a beforeClass hook + ReflectionAccessor::callMethod( + $testCase, + 'ensureKernelShutdown' + ); + foreach ($clientAttributes as [$property, $attribute]) { \assert($property instanceof \ReflectionProperty); \assert($attribute instanceof \ReflectionAttribute); diff --git a/tests/Controller/Security/TwoFactorAuthorizationTest.php b/tests/Controller/Security/TwoFactorAuthorizationTest.php index 0bbf6b79..485f38ff 100644 --- a/tests/Controller/Security/TwoFactorAuthorizationTest.php +++ b/tests/Controller/Security/TwoFactorAuthorizationTest.php @@ -61,11 +61,6 @@ public static function cleanUp(): void ->execute(); } - protected function setUp(): void - { - static::ensureKernelShutdown(); - } - public function testLoginRedirectEnable2fa(): void { static::assertTrue(self::$user->needToEnableTotpAuthenticationEnabled());