Skip to content

Commit

Permalink
fix test tear down
Browse files Browse the repository at this point in the history
  • Loading branch information
g5bot committed Dec 18, 2024
1 parent 78b5d7c commit ea80807
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
20 changes: 10 additions & 10 deletions tests/StuMocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);

Expand All @@ -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();
}
}
10 changes: 9 additions & 1 deletion tests/TwigTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, mixed> $requestVars*/
Expand Down
5 changes: 0 additions & 5 deletions tests/inttest/html/AllViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit ea80807

Please sign in to comment.