39 lines
1.3 KiB
PHP
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);
|
|
}
|
|
}
|
|
}
|