first commit
This commit is contained in:
87
tests/Kernel/RuntimePathsTest.php
Normal file
87
tests/Kernel/RuntimePathsTest.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Kernel;
|
||||
|
||||
use Netig\Netslim\Kernel\Runtime\RuntimePaths;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class RuntimePathsTest extends TestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
RuntimePaths::resetApplicationRoot();
|
||||
RuntimePaths::resetProjectRoot();
|
||||
}
|
||||
|
||||
public function testGetProjectRootReturnsRepositoryRoot(): void
|
||||
{
|
||||
self::assertSame(dirname(__DIR__, 2), RuntimePaths::getProjectRoot());
|
||||
}
|
||||
|
||||
public function testGetConfigPathReturnsRootConfigDirectoryAndFilePath(): void
|
||||
{
|
||||
self::assertSame(dirname(__DIR__, 2) . '/config', RuntimePaths::getConfigPath());
|
||||
self::assertSame(dirname(__DIR__, 2) . '/config/modules.php', RuntimePaths::getConfigPath('modules.php'));
|
||||
}
|
||||
|
||||
public function testApplicationRootDefaultsToProjectRoot(): void
|
||||
{
|
||||
self::assertSame(dirname(__DIR__, 2), RuntimePaths::getApplicationRoot());
|
||||
self::assertSame(dirname(__DIR__, 2) . '/config', RuntimePaths::getApplicationConfigPath());
|
||||
}
|
||||
|
||||
public function testApplicationRootCanPointToFixtureApplication(): void
|
||||
{
|
||||
RuntimePaths::setApplicationRoot(dirname(__DIR__, 2) . '/tests/Fixtures/Application');
|
||||
|
||||
self::assertSame(dirname(__DIR__, 2) . '/tests/Fixtures/Application', RuntimePaths::getApplicationRoot());
|
||||
self::assertSame(dirname(__DIR__, 2) . '/tests/Fixtures/Application/config/modules.php', RuntimePaths::getApplicationConfigPath('modules.php'));
|
||||
self::assertSame(dirname(__DIR__, 2) . '/tests/Fixtures/Application/templates/Kernel', RuntimePaths::getApplicationPath('templates/Kernel'));
|
||||
}
|
||||
|
||||
public function testGetTwigCacheReturnsFalseInDev(): void
|
||||
{
|
||||
self::assertFalse(RuntimePaths::getTwigCache(true));
|
||||
}
|
||||
|
||||
public function testGetTwigCacheReturnsCachePathOutsideDev(): void
|
||||
{
|
||||
$cachePath = RuntimePaths::getTwigCache(false);
|
||||
|
||||
self::assertIsString($cachePath);
|
||||
self::assertStringEndsWith('/var/cache/twig', $cachePath);
|
||||
}
|
||||
|
||||
public function testGetDatabasePathCreatesDatabaseFileWhenMissing(): void
|
||||
{
|
||||
$dbFile = dirname(__DIR__, 2) . '/database/app.sqlite';
|
||||
$dbDir = dirname($dbFile);
|
||||
$backup = $dbFile . '.bak-test';
|
||||
|
||||
if (file_exists($backup)) {
|
||||
@unlink($backup);
|
||||
}
|
||||
|
||||
if (file_exists($dbFile)) {
|
||||
rename($dbFile, $backup);
|
||||
}
|
||||
|
||||
@unlink($dbFile);
|
||||
|
||||
try {
|
||||
$path = RuntimePaths::getDatabasePath();
|
||||
|
||||
self::assertSame($dbFile, $path);
|
||||
self::assertDirectoryExists($dbDir);
|
||||
self::assertFileExists($dbFile);
|
||||
} finally {
|
||||
@unlink($dbFile);
|
||||
if (file_exists($backup)) {
|
||||
rename($backup, $dbFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user