Working state
This commit is contained in:
@@ -6,43 +6,43 @@ namespace Tests\Shared;
|
||||
use App\Shared\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use ReflectionProperty;
|
||||
use Slim\Factory\AppFactory;
|
||||
use Slim\App;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
|
||||
final class BootstrapTest extends TestCase
|
||||
{
|
||||
/** @var array<string, string> */
|
||||
private array $envBackup = [];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->envBackup = $_ENV;
|
||||
$this->envBackup = [
|
||||
'APP_AUTO_PROVISION' => $_ENV['APP_AUTO_PROVISION'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$_ENV = $this->envBackup;
|
||||
foreach ($this->envBackup as $key => $value) {
|
||||
if ($value === null) {
|
||||
unset($_ENV[$key]);
|
||||
} else {
|
||||
$_ENV[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetContainerReturnsPreloadedContainer(): void
|
||||
public function testInitializeInfrastructureReturnsPreloadedContainer(): void
|
||||
{
|
||||
$bootstrap = Bootstrap::create();
|
||||
$container = new class implements ContainerInterface {
|
||||
public function get(string $id): mixed
|
||||
{
|
||||
throw new \RuntimeException('Not expected');
|
||||
}
|
||||
$container = $this->createStub(ContainerInterface::class);
|
||||
|
||||
public function has(string $id): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
$this->setPrivate($bootstrap, 'container', $container);
|
||||
|
||||
$this->setPrivateProperty($bootstrap, 'container', $container);
|
||||
|
||||
self::assertSame($container, $bootstrap->getContainer());
|
||||
self::assertSame($container, $bootstrap->initializeInfrastructure());
|
||||
self::assertSame($container, $bootstrap->getContainer());
|
||||
}
|
||||
|
||||
public function testCreateHttpAppReturnsPreloadedApp(): void
|
||||
@@ -50,40 +50,29 @@ final class BootstrapTest extends TestCase
|
||||
$bootstrap = Bootstrap::create();
|
||||
$app = AppFactory::create();
|
||||
|
||||
$this->setPrivateProperty($bootstrap, 'app', $app);
|
||||
$this->setPrivate($bootstrap, 'app', $app);
|
||||
|
||||
self::assertSame($app, $bootstrap->createHttpApp());
|
||||
}
|
||||
|
||||
public function testInitializeReturnsPreloadedAppWhenAutoProvisioningDisabled(): void
|
||||
public function testInitializeReturnsPreloadedAppWhenAutoProvisionIsDisabled(): void
|
||||
{
|
||||
$_ENV['APP_ENV'] = 'production';
|
||||
$_ENV['APP_AUTO_PROVISION'] = '0';
|
||||
|
||||
$bootstrap = Bootstrap::create();
|
||||
$container = new class implements ContainerInterface {
|
||||
public function get(string $id): mixed
|
||||
{
|
||||
throw new \RuntimeException('Not expected');
|
||||
}
|
||||
|
||||
public function has(string $id): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
$container = $this->createStub(ContainerInterface::class);
|
||||
$app = AppFactory::create();
|
||||
|
||||
$this->setPrivateProperty($bootstrap, 'container', $container);
|
||||
$this->setPrivateProperty($bootstrap, 'app', $app);
|
||||
$this->setPrivate($bootstrap, 'container', $container);
|
||||
$this->setPrivate($bootstrap, 'app', $app);
|
||||
|
||||
self::assertSame($app, $bootstrap->initialize());
|
||||
}
|
||||
|
||||
private function setPrivateProperty(object $object, string $property, mixed $value): void
|
||||
private function setPrivate(Bootstrap $bootstrap, string $property, mixed $value): void
|
||||
{
|
||||
$reflection = new \ReflectionProperty($object, $property);
|
||||
$reflection = new ReflectionProperty($bootstrap, $property);
|
||||
$reflection->setAccessible(true);
|
||||
$reflection->setValue($object, $value);
|
||||
$reflection->setValue($bootstrap, $value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user