Files
KantSites/tests/KernelCacheTest.php
kantarci 7c1c86b864
CMS quality / php (8.2) (push) Canceled after 0s
CMS quality / php (8.4) (push) Canceled after 0s
CMS quality / browser (push) Canceled after 0s
CMS quality / mysql (push) Canceled after 0s
fix: preserve running kernel cache during archive updates
2026-09-14 15:35:52 +02:00

39 lines
1.3 KiB
PHP

<?php
namespace App\Tests;
use App\Kernel;
use PHPUnit\Framework\TestCase;
final class KernelCacheTest extends TestCase
{
public function testAnUpdateKeepsTheRunningCacheAndSelectsANewOneForTheNextRequest(): void
{
$root = sys_get_temp_dir().'/kant-cache-'.bin2hex(random_bytes(6));
mkdir($root);
$kernel = static fn (): Kernel => new class($root) extends Kernel {
public function __construct(private string $root)
{
parent::__construct('prod', false);
}
public function getProjectDir(): string
{
return $this->root;
}
};
try {
file_put_contents($root.'/VERSION', "1.10.1\n");
$running = $kernel();
$old = $running->getCacheDir();
self::assertSame($old, $kernel()->getCacheDir());
file_put_contents($root.'/VERSION', "1.10.2\n");
self::assertSame($old, $running->getCacheDir(), 'The active request retains its cache even after VERSION changes.');
self::assertNotSame($old, $kernel()->getCacheDir(), 'A new kernel must not reuse the previous compiled container or Twig templates.');
} finally {
unlink($root.'/VERSION');
rmdir($root);
}
}
}