ldc-cocotte/tests/Feature/App/Console/ConfigCacheTest.php
Jérémy Munsch e9a6889b13
test(ConfigCache): add test for caching configuration
Ensure configuration caching works without non-serializable values.
2026-11-18 10:48:46 +01:00

47 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature\App\Console;
use Illuminate\Support\Facades\File;
use Illuminate\Testing\PendingCommand;
use Webmozart\Assert\Assert;
use function Pest\Laravel\artisan;
describe('App\Console\ConfigCache', function (): void {
it('caches configuration without non-serializable values', function (): void {
// GIVEN
$previousEnv = $_ENV['APP_CONFIG_CACHE'] ?? null;
$previousServer = $_SERVER['APP_CONFIG_CACHE'] ?? null;
$tempConfigPath = sys_get_temp_dir() . '/cocotte-config-cache-' . uniqid('', true) . '.php';
$_ENV['APP_CONFIG_CACHE'] = $tempConfigPath;
$_SERVER['APP_CONFIG_CACHE'] = $tempConfigPath;
try {
// WHEN
$command = artisan('config:cache');
Assert::isInstanceOf($command, PendingCommand::class);
// THEN
$command->assertSuccessful()->execute();
expect(File::exists($tempConfigPath))->toBeTrue();
} finally {
File::delete($tempConfigPath);
if ($previousEnv === null) {
unset($_ENV['APP_CONFIG_CACHE']);
} else {
$_ENV['APP_CONFIG_CACHE'] = $previousEnv;
}
if ($previousServer === null) {
unset($_SERVER['APP_CONFIG_CACHE']);
} else {
$_SERVER['APP_CONFIG_CACHE'] = $previousServer;
}
}
});
});