host = __DIR__.'/../../storage/framework/testing/boot-overlay-'.bin2hex(random_bytes(6)); mkdir($this->host.'/app/Providers', 0700, true); mkdir($this->host.'/app/Shared/Context', 0700, true); file_put_contents($this->host.'/app/Providers/AppServiceProvider.php', 'app->scoped(CompanyContext::class); }'."\npublic function boot(): void\n {\n }\n}"); }); afterEach(function () { foreach (['app/Providers/AppServiceProvider.php', 'app/Shared/Context/ModuleNavigation.php'] as $file) { unlink($this->host.'/'.$file); } foreach (['app/Providers', 'app/Shared/Context', 'app/Shared', 'app', ''] as $directory) { rmdir($this->host.($directory === '' ? '' : '/'.$directory)); } }); test('prepares legacy host without changing source files or grants', function () { $file = $this->host.'/app/Shared/Context/ModuleNavigation.php'; $before = "['purchasing_budget.', 'supplier_payables.']]; }"; file_put_contents($file, $before); $result = BootOverlay::prepare($this->host); expect($result['app/Shared/Context/ModuleNavigation.php']['contents'])->toContain("'purchasing_requisitions.'") ->and(file_get_contents($file))->toBe($before); }); test('preserves expanded host navigation and is repeatable', function () { $before = " ['purchasing_budget.', 'purchasing_requisitions.', 'purchasing_orders.', 'purchasing_invoices.', 'supplier_payables.']]; }"; file_put_contents($this->host.'/app/Shared/Context/ModuleNavigation.php', $before); $result = BootOverlay::prepare($this->host); expect($result['app/Shared/Context/ModuleNavigation.php']['contents'])->toBe($before); foreach ($result as $file => $entry) { file_put_contents($this->host.'/'.$file, $entry['contents']); } $again = BootOverlay::prepare($this->host); foreach ($result as $file => $entry) { expect($again[$file]['contents'])->toBe($entry['contents']); } }); test('refuses ambiguous or executable host prefix lists', function (string $navigation) { file_put_contents($this->host.'/app/Shared/Context/ModuleNavigation.php', $navigation); expect(fn () => BootOverlay::prepare($this->host))->toThrow(RuntimeException::class); })->with([ 'unknown expression' => "['purchasing_budget.', dynamicPrefix(), 'supplier_payables.']]; }", 'missing anchor' => "['supplier_payables.']]; }", 'duplicate' => "['purchasing_budget.', 'supplier_payables.'], 'purchasing'=>['purchasing_budget.', 'supplier_payables.']]; }", ]);