From ea80807e3d1ef48c18ec70fe8eb01dee53645a6d Mon Sep 17 00:00:00 2001 From: Janko Date: Wed, 18 Dec 2024 14:09:04 +0100 Subject: [PATCH] fix test tear down --- tests/StuMocks.php | 20 ++++++++++---------- tests/TwigTestCase.php | 10 +++++++++- tests/inttest/html/AllViewControllerTest.php | 5 ----- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/tests/StuMocks.php b/tests/StuMocks.php index e68d2ecb4..03d51e49f 100644 --- a/tests/StuMocks.php +++ b/tests/StuMocks.php @@ -13,12 +13,7 @@ class StuMocks { private static ?StuMocks $INSTANCE = null; - private StuContainer $dic; - - private function __construct() - { - $this->dic = Init::getContainer(); - } + private function __construct() {} public static function get(): StuMocks { @@ -31,14 +26,14 @@ public static function get(): StuMocks public function mockService(string $id, mixed $serviceMock): StuMocks { - $this->dic->setAdditionalService($id, $serviceMock); + $this->getStuContainer()->setAdditionalService($id, $serviceMock); return $this; } public function registerStubbedComponent(ComponentEnumInterface $componentEnum): StuMocks { - $this->dic + $this->getStuContainer() ->get(ComponentLoaderInterface::class) ->registerStubbedComponent($componentEnum); @@ -47,9 +42,14 @@ public function registerStubbedComponent(ComponentEnumInterface $componentEnum): public function reset(): void { - $this->dic->clearAdditionalServices(); - $this->dic + $this->getStuContainer()->clearAdditionalServices(); + $this->getStuContainer() ->get(ComponentLoaderInterface::class) ->resetStubbedComponents(); } + + private function getStuContainer(): StuContainer + { + return Init::getContainer(); + } } diff --git a/tests/TwigTestCase.php b/tests/TwigTestCase.php index 0dd3c8a9c..12a19526a 100644 --- a/tests/TwigTestCase.php +++ b/tests/TwigTestCase.php @@ -52,14 +52,22 @@ abstract class TwigTestCase extends StuTestCase public function setUp(): void { $this->initializeSchema(); + } + #[Override] + public function tearDown(): void + { $dic = $this->getContainer(); - $dic->get(GameControllerInterface::class)->resetGameData(); $dic->get(TwigPageInterface::class)->resetVariables(); $dic->get(ComponentRegistrationInterface::class)->resetComponents(); } + public static function tearDownAfterClass(): void + { + StuMocks::get()->reset(); + } + protected abstract function getViewControllerClass(): string; /** @param array $requestVars*/ diff --git a/tests/inttest/html/AllViewControllerTest.php b/tests/inttest/html/AllViewControllerTest.php index c8f38e073..ccf2e263e 100644 --- a/tests/inttest/html/AllViewControllerTest.php +++ b/tests/inttest/html/AllViewControllerTest.php @@ -77,11 +77,6 @@ public static function setUpBeforeClass(): void ->registerStubbedComponent(GameComponentEnum::USER); } - public static function tearDownAfterClass(): void - { - StuMocks::get()->reset(); - } - #[Override] protected function getSnapshotId(): string {