settingsPath = ExtensionStoragePath::module('sirsoft-ecommerce', 'settings').'/order_settings.json'; $this->hadOriginalSettings = File::exists($this->settingsPath); $this->originalSettings = $this->hadOriginalSettings ? File::get($this->settingsPath) : null; File::ensureDirectoryExists(dirname($this->settingsPath)); } protected function tearDown(): void { if ($this->hadOriginalSettings && $this->originalSettings !== null) { File::put($this->settingsPath, $this->originalSettings); } else { File::delete($this->settingsPath); } parent::tearDown(); } /** * @scenario method_kind=extension, capability_declared=declared, capability=pg_locked * * @effects upgrade_step_backfills_settings_file, saved_null_pg_provider_self_healed */ public function test_backfills_pg_declaration_for_nicepay_easy_pay_methods(): void { $this->writeSettings([ ['id' => 'card', 'pg_provider' => 'nicepayments'], ['id' => 'nicepay_naverpay', 'pg_provider' => null, 'is_active' => true], ['id' => 'nicepay_kakaopay', 'pg_provider' => null, 'is_active' => true], ]); $this->runMigration(); $methods = $this->readMethods(); foreach (['nicepay_naverpay', 'nicepay_kakaopay'] as $id) { $method = $methods[$id]; $this->assertSame('nicepayments', $method['pg_provider'], "{$id} 의 PG 가 고정되어야 한다"); $this->assertTrue($method['pg_locked']); $this->assertTrue($method['needs_pg']); $this->assertSame('pg', $method['refund_method']); $this->assertTrue($method['is_active']); } } public function test_does_not_touch_other_plugins_or_builtin_methods(): void { $this->writeSettings([ ['id' => 'card', 'pg_provider' => 'nicepayments'], ['id' => 'dbank', 'pg_provider' => ''], ['id' => 'nhnkcp_naverpay', 'pg_provider' => null], ['id' => 'nicepay_naverpay', 'pg_provider' => null], ]); $this->runMigration(); $methods = $this->readMethods(); $this->assertSame('nicepayments', $methods['card']['pg_provider']); $this->assertArrayNotHasKey('pg_locked', $methods['card']); $this->assertSame('', $methods['dbank']['pg_provider']); $this->assertArrayNotHasKey('pg_locked', $methods['dbank']); $this->assertNull($methods['nhnkcp_naverpay']['pg_provider']); $this->assertArrayNotHasKey('pg_locked', $methods['nhnkcp_naverpay']); $this->assertSame('nicepayments', $methods['nicepay_naverpay']['pg_provider']); } /** * @scenario method_kind=extension, capability_declared=declared, capability=pg_locked * * @effects upgrade_step_backfills_settings_file */ public function test_is_idempotent(): void { $this->writeSettings([ ['id' => 'nicepay_naverpay', 'pg_provider' => null], ]); $this->runMigration(); $first = File::get($this->settingsPath); $this->runMigration(); $second = File::get($this->settingsPath); $this->assertSame($first, $second, '재실행해도 결과가 달라지지 않아야 한다'); } public function test_skips_when_settings_file_is_missing(): void { File::delete($this->settingsPath); $this->runMigration(); $this->assertFalse(File::exists($this->settingsPath)); } public function test_skips_when_settings_json_is_malformed(): void { File::put($this->settingsPath, '{ not valid json'); $this->runMigration(); $this->assertSame('{ not valid json', File::get($this->settingsPath)); } /** * @param array> $paymentMethods */ private function writeSettings(array $paymentMethods): void { File::put($this->settingsPath, json_encode([ 'payment_methods' => $paymentMethods, ], JSON_THROW_ON_ERROR)); } /** * @return array> 결제수단 ID => 설정 */ private function readMethods(): array { $settings = json_decode(File::get($this->settingsPath), true, flags: JSON_THROW_ON_ERROR); $keyed = []; foreach ($settings['payment_methods'] as $method) { $keyed[$method['id']] = $method; } return $keyed; } private function runMigration(): void { (new BackfillEasyPayPgProvider)->run(new UpgradeContext( fromVersion: '1.0.0-beta.3', toVersion: '1.0.0-beta.4', currentStep: '1.0.0-beta.4', )); } }