$this->hadConfig = file_exists(config_path('manager.php'))); afterEach(fn () => $this->hadConfig || @unlink(config_path('manager.php'))); function doctorReport(): array { Artisan::call('manager:doctor', ['--json' => true]); return json_decode(Artisan::output(), true); } it('reports a healthy setup as JSON with exit code 0', function () { $report = doctorReport(); $status = collect($report['checks'])->pluck('status', 'check'); expect($status['user_trait'])->toBe('ok') ->and($status['tables'])->toBe('ok') ->and($status['routes'])->toBe('ok') ->and($report['ok'])->toBeTrue(); }); it('fails with a fix when the user model is not a class', function () { config(['manager.user_model' => 'Nope\\User']); $check = collect(doctorReport()['checks'])->firstWhere('check', 'user_model'); expect($check['status'])->toBe('fail')->and($check['fix'])->toContain('MANAGER_USER_MODEL'); expect(Artisan::call('manager:doctor'))->toBe(1); }); it('warns when there is no super admin yet', function () { $check = collect(doctorReport()['checks'])->firstWhere('check', 'super_admin'); expect($check['status'])->toBe('warn')->and($check['fix'])->toContain('manager:create-user'); }); it('lists the tables of the active modules', function () { $tables = collect(app(ModuleRegistry::class)->active())->flatMap->tables(); expect($tables)->toContain('media', 'posts'); }); it('refuses an unknown module in the installer', function () { expect(Artisan::call('manager:install', ['--modules' => 'users,nonsense']))->toBe(1); }); it('writes the switches to .env', function () { $env = base_path('.env'); $before = file_exists($env) ? file_get_contents($env) : null; Artisan::call('manager:install', ['--modules' => 'users,media,posts', '--path' => 'admin']); $written = file_get_contents($env); $before === null ? unlink($env) : file_put_contents($env, $before); expect($written)->toContain('MANAGER_PATH=admin')->toContain('MANAGER_AUDIT=false')->toContain('MANAGER_POSTS=true'); });