56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Shared;
|
|
|
|
use App\Shared\Config;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
|
|
|
final class ConfigTest extends TestCase
|
|
{
|
|
public function testGetTwigCacheReturnsFalseInDev(): void
|
|
{
|
|
self::assertFalse(Config::getTwigCache(true));
|
|
}
|
|
|
|
public function testGetTwigCacheReturnsCachePathOutsideDev(): void
|
|
{
|
|
$cachePath = Config::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 = Config::getDatabasePath();
|
|
|
|
self::assertSame($dbFile, $path);
|
|
self::assertDirectoryExists($dbDir);
|
|
self::assertFileExists($dbFile);
|
|
} finally {
|
|
@unlink($dbFile);
|
|
if (file_exists($backup)) {
|
|
rename($backup, $dbFile);
|
|
}
|
|
}
|
|
}
|
|
}
|