|null 원본 argv 백업 */ private ?array $originalArgv = null; protected function tearDown(): void { if ($this->originalArgv !== null) { $_SERVER['argv'] = $this->originalArgv; $this->originalArgv = null; } parent::tearDown(); } /** * 주어진 argv[1] 로 $_SERVER['argv'] 를 임시 설정하고 콜백을 실행합니다. * * @param string $command artisan 명령명 (argv[1] 위치) * @param callable $callback argv 설정 상태에서 실행할 코드 */ private function withArgv(string $command, callable $callback): void { if ($this->originalArgv === null) { $this->originalArgv = $_SERVER['argv'] ?? []; } $_SERVER['argv'] = ['artisan', $command]; try { $callback(); } finally { $_SERVER['argv'] = $this->originalArgv; $this->originalArgv = null; } } public function test_returns_true_for_migrate(): void { $this->withArgv('migrate', function () { $this->assertTrue(InstallerContext::isSchemaMutatingCommand()); }); } public function test_returns_true_for_migrate_fresh(): void { $this->withArgv('migrate:fresh', function () { $this->assertTrue(InstallerContext::isSchemaMutatingCommand()); }); } public function test_returns_true_for_migrate_refresh(): void { // migrate:refresh 는 참조 구현(LanguagePackServiceProvider)에 누락돼 있던 명령. // 스키마를 drop/recreate 하므로 동일한 빈 DB 구간을 만든다 → 반드시 포함. $this->withArgv('migrate:refresh', function () { $this->assertTrue(InstallerContext::isSchemaMutatingCommand()); }); } public function test_returns_true_for_migrate_rollback(): void { $this->withArgv('migrate:rollback', function () { $this->assertTrue(InstallerContext::isSchemaMutatingCommand()); }); } public function test_returns_true_for_migrate_reset(): void { $this->withArgv('migrate:reset', function () { $this->assertTrue(InstallerContext::isSchemaMutatingCommand()); }); } public function test_returns_true_for_db_wipe(): void { $this->withArgv('db:wipe', function () { $this->assertTrue(InstallerContext::isSchemaMutatingCommand()); }); } public function test_returns_false_for_non_migration_command(): void { $this->withArgv('serve', function () { $this->assertFalse(InstallerContext::isSchemaMutatingCommand()); }); } public function test_returns_false_for_route_list(): void { $this->withArgv('route:list', function () { $this->assertFalse(InstallerContext::isSchemaMutatingCommand()); }); } }