fix: preserve running kernel cache during archive updates
This commit is contained in:
1 parent
c82a37643b
commit
7c1c86b864
9 files changed
+176
-19
No files matched your search
@@ -0,0 +1,38 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user