|
4 | 4 |
|
5 | 5 | namespace SymPress\Runtime\Tests\Integration; |
6 | 6 |
|
| 7 | +use PHPUnit\Framework\Attributes\DataProvider; |
7 | 8 | use PHPUnit\Framework\Attributes\Group; |
8 | 9 | use SymPress\Runtime\Tests\Support\TemporaryProject; |
9 | 10 | use Symfony\Component\Process\Process; |
@@ -85,4 +86,38 @@ public function testInvalidRuntimeOptionsStillProduceStructuredRedactedDiagnosti |
85 | 86 | $report = json_decode($failed->getOutput(), true, flags: JSON_THROW_ON_ERROR); |
86 | 87 | self::assertSame('fail', array_column($report['checks'], 'status', 'id')['configuration']); |
87 | 88 | } |
| 89 | + |
| 90 | + /** @return iterable<string, array{bool, bool}> */ |
| 91 | + public static function kernelFreeLayouts(): iterable |
| 92 | + { |
| 93 | + yield 'ordinary layout' => [false, false]; |
| 94 | + yield 'core in root' => [true, false]; |
| 95 | + yield 'unused unsafe cache' => [false, true]; |
| 96 | + yield 'core in root with unused unsafe cache' => [true, true]; |
| 97 | + } |
| 98 | + |
| 99 | + #[DataProvider('kernelFreeLayouts')] |
| 100 | + #[Group('PAR-SYM-001')] |
| 101 | + public function testKernelFreeWordPressDoesNotInspectUnusedKernelDirectories(bool $coreInRoot, bool $unsafeCache): void |
| 102 | + { |
| 103 | + $this->fixture(); |
| 104 | + if ($coreInRoot) { |
| 105 | + $this->write('composer.json', '{"extra":{"wordpress-install-dir":".","sympress-runtime":{}}}'); |
| 106 | + $this->write('wp-load.php', '<?php // WordPress core in the project root'); |
| 107 | + } |
| 108 | + if ($unsafeCache) { |
| 109 | + $this->write('unused-cache/production/kernel/meta.php', 'unused'); |
| 110 | + chmod($this->root . '/unused-cache/production/kernel', 0770); |
| 111 | + $this->write('.env', (string) file_get_contents($this->root . '/.env') . "APP_CACHE_DIR=unused-cache\n"); |
| 112 | + } |
| 113 | + $process = $this->diagnose(); |
| 114 | + self::assertSame(0, $process->getExitCode(), $process->getOutput() . $process->getErrorOutput()); |
| 115 | + $report = json_decode($process->getOutput(), true, flags: JSON_THROW_ON_ERROR); |
| 116 | + $checks = array_column($report['checks'], 'status', 'id'); |
| 117 | + foreach (['kernel.cache', 'kernel.build', 'permissions.kernel-cache', 'permissions.kernel-build'] as $id) { |
| 118 | + self::assertSame('not-applicable', $checks[$id]); |
| 119 | + } |
| 120 | + self::assertFileDoesNotExist($this->root . '/.env.cached.php'); |
| 121 | + self::assertDirectoryDoesNotExist($this->root . '/var'); |
| 122 | + } |
88 | 123 | } |
0 commit comments