refactor(batch): 去重阻断warning组装提炼BatchDispatchWarning并加单测

This commit is contained in:
萝卜
2026-03-17 18:52:08 +08:00
parent aefecd0cbe
commit ea70f24535
3 changed files with 87 additions and 27 deletions

View File

@@ -0,0 +1,36 @@
<?php
namespace Tests\Unit;
use App\Support\BatchDispatchWarning;
use PHPUnit\Framework\TestCase;
class BatchDispatchWarningBuildTest extends TestCase
{
public function test_build_should_include_run_id_in_warning_and_actions_when_run_id_present(): void
{
$flash = BatchDispatchWarning::build('BAS ', 'BAS202603171234560001', 'bas');
$this->assertIsArray($flash);
$this->assertArrayHasKey('warning', $flash);
$this->assertStringContainsString('run_id=', (string) $flash['warning']);
$this->assertSame('进入上次批次复盘', (string) ($flash['warning_link_label'] ?? ''));
$this->assertStringContainsString('type=bas', (string) ($flash['warning_link_href'] ?? ''));
$this->assertSame('BAS202603171234560001', (string) ($flash['warning_copy_text'] ?? ''));
$this->assertSame('复制run_id', (string) ($flash['warning_copy_label'] ?? ''));
}
public function test_build_should_not_include_actions_when_run_id_missing(): void
{
$flash = BatchDispatchWarning::build('BMPA ', '', 'bmpa');
$this->assertIsArray($flash);
$this->assertArrayHasKey('warning', $flash);
$this->assertStringNotContainsString('run_id=', (string) $flash['warning']);
$this->assertArrayNotHasKey('warning_link_href', $flash);
$this->assertArrayNotHasKey('warning_copy_text', $flash);
}
}