Files
breadcrumb-the-shire/tests/Support/AppContainerIsolationTraitTest.php

71 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
namespace MintyPHP\Tests\Support;
use MintyPHP\App\AppContainer;
use PHPUnit\Framework\TestCase;
final class AppContainerIsolationTraitTest extends TestCase
{
public function testPushAndRestoreRoundTripKeepsOriginalGlobalContainer(): void
{
$original = $GLOBALS['minty_app_container'];
self::assertInstanceOf(AppContainer::class, $original);
$harness = new class () {
use AppContainerIsolationTrait;
public function push(AppContainer $container): void
{
$this->pushAppContainer($container);
}
public function restore(): void
{
$this->restoreAppContainer();
}
};
$replacement = new AppContainer();
$harness->push($replacement);
self::assertSame($replacement, $GLOBALS['minty_app_container']);
$harness->restore();
self::assertSame($original, $GLOBALS['minty_app_container']);
}
public function testMultiplePushesRestoreToInitialContainer(): void
{
$original = $GLOBALS['minty_app_container'];
self::assertInstanceOf(AppContainer::class, $original);
$harness = new class () {
use AppContainerIsolationTrait;
public function push(AppContainer $container): void
{
$this->pushAppContainer($container);
}
public function restore(): void
{
$this->restoreAppContainer();
}
};
$first = new AppContainer();
$second = new AppContainer();
$harness->push($first);
$harness->push($second);
self::assertSame($second, $GLOBALS['minty_app_container']);
$harness->restore();
self::assertSame($original, $GLOBALS['minty_app_container']);
}
}