Files
tcpserver-flow/tests/flow/cases/BlockTest.php
T
zimoyin 3471deb3f1 ai-refactor(flow): 调整抽象流程节点实现和依赖路径
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext
- 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示
- 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法
- 增加日志记录细节,便于调试策略执行中断时的错误信息
- 优化代码注释,提升代码可读性和维护性
2026-03-11 02:40:45 +08:00

175 lines
5.3 KiB
PHP

<?php
namespace tests\flow\cases;
use app\config\Config;
use app\flow\config\ProcessConfig;
use app\flow\ProcessEngine;
use app\utils\Logger;
use tests\flow\TestCase;
use tests\flow\VirtualityFlowProcessor;
/**
* 流程阻断逻辑测试
*
* 覆盖场景:
* 7. 流程阻断逻辑正确性
*/
class BlockTest extends TestCase
{
private VirtualityFlowProcessor $processor;
private bool $originalBlockMode;
protected function setUp(): void
{
parent::setUp();
$this->processor = VirtualityFlowProcessor::createStandard();
// 保存原始 blockMode 值
$this->originalBlockMode = Config::getInstance()->blockMode;
}
protected function tearDown(): void
{
parent::tearDown();
$this->processor->reset();
// 恢复原始 blockMode 值
Config::getInstance()->blockMode = $this->originalBlockMode;
}
// ==================== 7. 流程阻断逻辑正确性 ====================
/**
* 测试流程链正确执行
*/
public function testProcessChainExecution(): void
{
$engine = ProcessEngine::createStandard();
// 验证流程链已构建
$nodes = $engine->getNodes();
$this->assertNotEmpty($nodes, '流程链应包含节点');
}
/**
* 测试禁用节点后的流程
*/
public function testDisabledNodeSkipped(): void
{
$config = ProcessConfig::createStandard();
$config->skipStep('晨洗');
$processor = VirtualityFlowProcessor::create($config);
$result = $processor->swipe('操作员1', '胃镜1', '清洗');
// 晨洗被跳过,应该直接进入清洗
$this->assertSuccess($result);
$this->assertStep($result, '清洗');
}
/**
* 测试时间验证策略阻断 - 阻断模式开启
*
* 当 blockMode=true 时,清洗时长不达标应该返回错误
*/
public function testTimeValidationBlockWithBlockModeOn(): void
{
// 开启阻断模式
Config::getInstance()->blockMode = true;
// 创建一个时间不足的场景(只有5秒)
$context = $this->processor->createContextBuilder()
->endoscope('胃镜1')
->reader('漂洗')
->operator('操作员1')
->currentStep('清洗')
->duration(5) // 只有5秒,时间不足
->batchNo(date('Ymd') . '010001')
->build();
$engine = ProcessEngine::createStandard();
$result = $engine->execute($context);
// 阻断模式下,时间不足应该导致流程失败
$this->assertFalse($result->isSuccess(), '阻断模式下,时长不足应失败');
}
/**
* 测试时间验证策略 - 阻断模式关闭
*
* 当 blockMode=false 时,清洗时长不达标仍可继续,但应有提醒
*/
public function testTimeValidationWithBlockModeOff(): void
{
// 关闭阻断模式
Config::getInstance()->blockMode = false;
// 创建一个时间不足的场景
$context = $this->processor->createContextBuilder()
->endoscope('胃镜1')
->reader('漂洗')
->operator('操作员1')
->currentStep('清洗')
->duration(5) // 只有5秒,时间不足
->batchNo(date('Ymd') . '010001')
->build();
$engine = ProcessEngine::createStandard();
$result = $engine->execute($context);
// 非阻断模式下,时间不足应该可以继续流程
$this->assertTrue($result->isSuccess(), '非阻断模式下,时长不足应可继续');
}
/**
* 测试重复刷卡阻断
*/
public function testDuplicateSwipeBlock(): void
{
$operator = '操作员1';
$endoscope = '胃镜1';
// 完成清洗
$result1 = $this->processor->swipe($operator, $endoscope, '清洗');
$this->assertSuccess($result1);
// 继续漂洗
$result2 = $this->processor->swipe($operator, $endoscope, '漂洗');
// 重复刷漂洗卡
$result3 = $this->processor->swipe($operator, $endoscope, '漂洗');
// 获取语音,验证重复刷卡提示
$voice3 = $result3->getFullVoice();
$this->assertNotEmpty($voice3, '应有语音输出');
$this->assertStringContainsString('重复刷卡', $voice3, '语音应包含重复刷卡提示');
}
/**
* 测试时长达标时的正常流程
*/
public function testTimeValidationPass(): void
{
// 开启阻断模式
Config::getInstance()->blockMode = true;
// 创建时长达标的场景(120秒,超过最低要求)
$context = $this->processor->createContextBuilder()
->endoscope('胃镜1')
->reader('漂洗')
->operator('操作员1')
->currentStep('清洗')
->duration(120) // 120秒,时间充足
->batchNo(date('Ymd') . '010001')
->build();
$engine = ProcessEngine::createStandard();
$result = $engine->execute($context);
// 时长达标应该成功
$this->assertTrue($result->isSuccess(), '时长达标应成功');
}
}