hadConfig = file_exists(config_path('manager.php')); $this->env = file_exists(base_path('.env')) ? file_get_contents(base_path('.env')) : null; }); afterEach(function () { $this->hadConfig || @unlink(config_path('manager.php')); $this->env === null ? @unlink(base_path('.env')) : file_put_contents(base_path('.env'), $this->env); }); 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'); Artisan::call('manager:install', ['--modules' => 'users,media,posts', '--path' => 'admin']); $written = file_get_contents($env); expect($written)->toContain('MANAGER_PATH=admin')->toContain('MANAGER_AUDIT=false')->toContain('MANAGER_POSTS=true'); }); it('leaves the check to a new process after it changed the switches', function () { Artisan::call('manager:install', ['--path' => 'admin']); expect(Artisan::output())->toContain('manager:doctor')->not->toContain('[OK]'); });