CaiWuXiTong/tests/Feature/Business/FinanceImportIsolationTest.php
WuYongJie 36af0e211a 修复生产内存保护:网页限额与重型导入隔离 (#430)
网页设置 2GiB 内存边界;生产重型导入统一进入 1CPU/1GiB 独立容器,保留只读文件、互斥、超时清理和发布保护。相关回归与资源隔离测试通过。
2026-10-21 14:30:06 +08:00

34 lines
1.3 KiB
PHP

<?php
namespace Tests\Feature\Business;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Contracts\Console\Kernel;
use RuntimeException;
use Tests\Feature\FeatureTestCase;
class FinanceImportIsolationTest extends FeatureTestCase
{
public function test_actual_artisan_import_is_blocked_before_reading_files_in_production_web_runtime(): void
{
$this->app['env'] = 'production';
config(['finance_batch.container' => false]);
// Laravel intentionally disables command events during PHPUnit boot.
// Recreate the production event wiring before exercising real Artisan.
$kernel = app(Kernel::class);
$kernel->rerouteSymfonyCommandEvents();
$kernel->setArtisan(null);
$blocked = false;
try {
Artisan::call('order-data:import-after-sales-cost', ['file' => '/does-not-exist.xlsx', '--dry-run' => true]);
} catch (RuntimeException $exception) {
$blocked = true;
$this->assertStringContainsString('run-finance-batch.sh', $exception->getMessage());
$this->assertDatabaseCount('ops_after_sales_cost_rows', 0);
} finally {
$this->app['env'] = 'testing';
}
$this->assertTrue($blocked, 'Production web runtime accepted a heavy import.');
}
}