diff --git a/tests/CreatesApplication.php b/tests/CreatesApplication.php index 61e9fda0..4d93cd52 100644 --- a/tests/CreatesApplication.php +++ b/tests/CreatesApplication.php @@ -3,6 +3,7 @@ namespace Tests; use Illuminate\Contracts\Console\Kernel; +use Illuminate\Database\DatabaseManager; use RuntimeException; trait CreatesApplication @@ -32,6 +33,23 @@ trait CreatesApplication throw new RuntimeException('测试环境未使用内存 SQLite,已拒绝执行以保护共享数据库。'); } + // Several migrations deliberately target the business_mirror connection. + // Force that connection onto its own in-memory SQLite database before + // RefreshDatabase runs, even when the developer's local .env points at + // the shared production mirror. + config([ + 'database.connections.business_mirror' => config('database.connections.sqlite'), + 'upstream_mirrors.connection' => 'business_mirror', + ]); + $app->make(DatabaseManager::class)->purge('business_mirror'); + + if ( + config('database.connections.business_mirror.driver') !== 'sqlite' + || config('database.connections.business_mirror.database') !== ':memory:' + ) { + throw new RuntimeException('测试业务镜像连接未使用内存 SQLite,已拒绝执行以保护共享数据库。'); + } + return $app; } } diff --git a/tests/Feature/Business/MarketingPlatformPromotionBillsTest.php b/tests/Feature/Business/MarketingPlatformPromotionBillsTest.php index 127c28a0..91373883 100644 --- a/tests/Feature/Business/MarketingPlatformPromotionBillsTest.php +++ b/tests/Feature/Business/MarketingPlatformPromotionBillsTest.php @@ -64,23 +64,36 @@ class MarketingPlatformPromotionBillsTest extends FeatureTestCase 'account' => 'account-01', ])); + $filename = '店铺营销账户账单_jd_2026-08.csv'; $response->assertOk() ->assertHeader('Content-Type', 'text/csv; charset=UTF-8') - ->assertDownload('店铺营销账户账单_jd_2026-08.csv'); + ->assertDownload('_jd_2026-08.csv'); + $this->assertStringContainsString( + "filename*=utf-8''" . rawurlencode($filename), + (string) $response->headers->get('Content-Disposition'), + ); $this->assertStringContainsString('测试店铺', $response->streamedContent()); } - public function test_removed_platform_promotion_directory_is_not_available(): void + public function test_removed_platform_promotion_directory_returns_to_the_current_page_with_feedback(): void { $this->allowMarketingAccountBillsPage(); + $this->withExceptionHandling(); + $this->loginAs(); + $currentPage = route('business.pages.show', [ + 'section' => 'billing-transactions', + 'page' => 'marketing-account-bills', + 'tab' => 'jd-promotion', + ]); - $this->loginAs() + $this->from($currentPage) ->get(route('business.pages.show', [ 'section' => 'billing-transactions', 'page' => 'platform-promotion-accounts', 'tab' => 'jd', ])) - ->assertNotFound(); + ->assertRedirect($currentPage) + ->assertSessionHas('errors'); } private function dashboardData(): array