Files
Investidor-V2/tests/Unit/RuntimeStorageTest.php
paulomassigue 14ad2f60c5
tests / ci (push) Canceled after 0s
header:navbar e footer
2026-10-19 13:07:16 +02:00

48 lines
1.9 KiB
PHP

<?php
namespace Tests\Unit;
use Illuminate\Filesystem\Filesystem;
use PHPUnit\Framework\TestCase;
class RuntimeStorageTest extends TestCase
{
public function test_missing_runtime_directories_are_created_without_changing_existing_files(): void
{
$root = sys_get_temp_dir().'/investmoz-runtime-'.bin2hex(random_bytes(8));
$prepare = require dirname(__DIR__, 2).'/bootstrap/storage.php';
try {
$prepare($root, $root.'/custom-storage');
foreach (['app/private', 'app/public', 'framework/cache/data', 'framework/sessions', 'framework/views', 'logs'] as $path) {
$this->assertDirectoryExists($root.'/custom-storage/'.$path);
}
$this->assertDirectoryExists($root.'/bootstrap/cache');
$file = $root.'/custom-storage/framework/views/existing.php';
file_put_contents($file, 'preserved');
$prepare($root, $root.'/custom-storage');
$this->assertSame('preserved', file_get_contents($file));
$this->assertNotFalse(realpath($root.'/custom-storage/framework/views'));
} finally {
(new Filesystem)->deleteDirectory($root);
}
}
public function test_a_file_blocking_a_runtime_directory_produces_an_actionable_error(): void
{
$root = sys_get_temp_dir().'/investmoz-runtime-'.bin2hex(random_bytes(8));
mkdir($root, 0775, true);
file_put_contents($root.'/storage', 'preserved');
$prepare = require dirname(__DIR__, 2).'/bootstrap/storage.php';
try {
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Cannot create Laravel runtime directory:');
$prepare($root, $root.'/storage');
} finally {
$this->assertSame('preserved', file_get_contents($root.'/storage'));
(new Filesystem)->deleteDirectory($root);
}
}
}