tempStepDir = storage_path('framework/testing/abstract-upgrade-'.uniqid()); File::ensureDirectoryExists($this->tempStepDir); } protected function tearDown(): void { if (File::isDirectory($this->tempStepDir)) { File::deleteDirectory($this->tempStepDir); } parent::tearDown(); } public function test_run_executes_migrations_in_filename_sorted_order(): void { $version = '0.0.10-test.order'; $token = 'V'.str_replace(['.', '-'], '_', $version); $dataDir = $this->tempStepDir.'/data/'.$version; File::ensureDirectoryExists($dataDir.'/migrations'); // 일부러 알파벳 역순으로 prefix 부여하여 파일명 정렬이 실제 실행 순서를 결정함을 검증 $this->writeMigrationFixture($dataDir.'/migrations/02_SecondStep.php', $token, 'SecondStep'); $this->writeMigrationFixture($dataDir.'/migrations/01_FirstStep.php', $token, 'FirstStep'); $this->writeMigrationFixture($dataDir.'/migrations/03_ThirdStep.php', $token, 'ThirdStep'); $step = $this->makeAnonymousStep($this->tempStepDir); $context = new UpgradeContext( fromVersion: '0.0.9', toVersion: $version, currentStep: $version, ); $captured = $this->captureMigrationCalls(); $step->run($context); $this->assertSame( ['FirstStep', 'SecondStep', 'ThirdStep'], $captured(), 'migrations 는 파일명 정렬 순서로 실행되어야 한다 (01 → 02 → 03)', ); } public function test_dataMigrations_strips_numeric_prefix_when_resolving_class_name(): void { $version = '0.0.11-test.prefix'; $token = 'V'.str_replace(['.', '-'], '_', $version); $dataDir = $this->tempStepDir.'/data/'.$version; File::ensureDirectoryExists($dataDir.'/migrations'); // 파일명: 01_PrefixStripped.php, 클래스명: PrefixStripped (prefix 없음) $this->writeMigrationFixture($dataDir.'/migrations/01_PrefixStripped.php', $token, 'PrefixStripped'); $step = $this->makeAnonymousStep($this->tempStepDir); $context = new UpgradeContext( fromVersion: '0.0.10', toVersion: $version, currentStep: $version, ); $captured = $this->captureMigrationCalls(); $step->run($context); $this->assertSame(['PrefixStripped'], $captured()); } public function test_run_skips_when_data_dir_absent(): void { $version = '0.0.12-test.empty'; $step = $this->makeAnonymousStep($this->tempStepDir); $context = new UpgradeContext( fromVersion: '0.0.11', toVersion: $version, currentStep: $version, ); // data/{version}/ 디렉토리 부재 — 예외 없이 silent return 되어야 한다 $step->run($context); $this->assertTrue(true); } /** * @param string $token 버전 namespace token (예: V0_0_10_test_order) */ private function writeMigrationFixture(string $filePath, string $token, string $className): void { $contents = << $GLOBALS['__abstract_upgrade_step_test_calls'] ?? []; } }