mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-20 21:01:38 +02:00
Added BootManangerTests and tweaked the BootManager a bit
This commit is contained in:
@@ -8,14 +8,14 @@ use DI\ContainerBuilder;
|
||||
class BootManager
|
||||
{
|
||||
/** Create the application service container. */
|
||||
public static function createContainer(string $configDirectory): Container
|
||||
public static function createContainer(string $configPath, string $cachePath): Container
|
||||
{
|
||||
$container = (new ContainerBuilder)->addDefinitions(
|
||||
...glob($configDirectory . '/*.php')
|
||||
...glob($configPath . '/*.php')
|
||||
);
|
||||
|
||||
if (self::enableContainerCompilation()) {
|
||||
$container->enableCompilation(dirname(__DIR__, 2) . '/cache');
|
||||
$container->enableCompilation($cachePath);
|
||||
}
|
||||
|
||||
return $container->build();
|
||||
|
@@ -14,7 +14,10 @@ ini_set('open_basedir', __DIR__);
|
||||
Dotenv::createUnsafeImmutable(__DIR__)->safeLoad();
|
||||
|
||||
// Initialize the container
|
||||
$container = BootManager::createContainer(__DIR__ . '/app/config');
|
||||
$container = BootManager::createContainer(
|
||||
__DIR__ . '/app/config',
|
||||
__DIR__ . '/app/cache'
|
||||
);
|
||||
|
||||
// Initialize the application
|
||||
$app = $container->call(AppManager::class);
|
||||
|
68
tests/Bootstrap/BootManagerTest.php
Normal file
68
tests/Bootstrap/BootManagerTest.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Bootstrap;
|
||||
|
||||
use App\Bootstrap\BootManager;
|
||||
use DI\Container;
|
||||
use Tests\TestCase;
|
||||
|
||||
/** @covers \App\Bootstrap\BootManager */
|
||||
class BootManagerTest extends TestCase
|
||||
{
|
||||
/** Path to the compiled container. */
|
||||
private const COMPILED_CONTAINER_PATH = 'app/cache/CompiledContainer.php';
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if (file_exists($this->filePath(self::COMPILED_CONTAINER_PATH))) {
|
||||
unlink($this->filePath(self::COMPILED_CONTAINER_PATH));
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_caches_the_container_when_compile_container_is_true(): void
|
||||
{
|
||||
putenv('APP_DEBUG=false');
|
||||
putenv('COMPILE_CONTAINER=true');
|
||||
|
||||
$container = BootManager::createContainer(
|
||||
$this->filePath('app/config'),
|
||||
$this->filePath('app/cache')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Container::class, $container);
|
||||
$this->assertFileExists($this->filePath(self::COMPILED_CONTAINER_PATH));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_does_not_cache_the_container_when_compilation_is_explicitly_disabled(): void
|
||||
{
|
||||
putenv('APP_DEBUG=false');
|
||||
putenv('COMPILE_CONTAINER=false');
|
||||
|
||||
$container = BootManager::createContainer(
|
||||
$this->filePath('app/config'),
|
||||
$this->filePath('app/cache')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Container::class, $container);
|
||||
$this->assertFileDoesNotExist($this->filePath('app/cache/CompiledContainer.php'));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_does_not_cache_the_container_when_debug_is_enabled(): void
|
||||
{
|
||||
putenv('APP_DEBUG=true');
|
||||
putenv('COMPILE_CONTAINER=true');
|
||||
|
||||
$container = BootManager::createContainer(
|
||||
$this->filePath('app/config'),
|
||||
$this->filePath('app/cache')
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(Container::class, $container);
|
||||
$this->assertFileDoesNotExist($this->filePath('app/cache/CompiledContainer.php'));
|
||||
}
|
||||
}
|
@@ -27,7 +27,8 @@ class TestCase extends BaseTestCase
|
||||
Dotenv::createUnsafeImmutable(__DIR__)->safeLoad();
|
||||
|
||||
$this->container = BootManager::createContainer(
|
||||
dirname(__DIR__) . '/app/config'
|
||||
dirname(__DIR__) . '/app/config',
|
||||
dirname(__DIR__) . '/app/cache'
|
||||
);
|
||||
|
||||
$this->config = new Config($this->container);
|
||||
|
2
tests/_files/app/config/.gitignore
vendored
Normal file
2
tests/_files/app/config/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
Reference in New Issue
Block a user