first commit
This commit is contained in:
53
tests/Shared/ConfigTest.php
Normal file
53
tests/Shared/ConfigTest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Shared;
|
||||
|
||||
use App\Shared\Config;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user