Files
tcpserver-flow/tests/flow/cases/ErrorFlowTest.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

119 lines
3.2 KiB
PHP

<?php
namespace tests\flow\cases;
use app\flow\ProcessEngine;
use tests\flow\TestCase;
use tests\flow\VirtualityFlowProcessor;
/**
* 错误刷卡流程测试
*
* 覆盖场景:
* 5. 错误刷卡流程
*/
class ErrorFlowTest extends TestCase
{
private VirtualityFlowProcessor $processor;
protected function setUp(): void
{
parent::setUp();
$this->processor = VirtualityFlowProcessor::createStandard();
}
protected function tearDown(): void
{
parent::tearDown();
$this->processor->reset();
}
// ==================== 5. 错误刷卡流程 ====================
/**
* 测试未刷人员卡直接刷内镜卡
*/
public function testSwipeEndoscopeWithoutOperator(): void
{
// 不刷人员卡,直接刷内镜卡
$result = $this->processor->swipeEndoscopeCard('胃镜1', '清洗');
$this->assertFailure($result, '未刷人员卡应失败');
$this->assertVoiceContains($result, '请刷人员卡');
}
/**
* 测试刷卡顺序错误 - 跳过清洗直接漂洗
*/
public function testWrongStepOrder(): void
{
$operator = '操作员1';
$endoscope = '胃镜1';
// 新流程,直接刷漂洗
$result = $this->processor->swipe($operator, $endoscope, '漂洗');
// 应该提示步骤顺序错误
// 注意:具体行为取决于流程引擎的实现
$this->assertNotNull($result);
}
/**
* 测试重复刷同一步骤的卡
*/
public function testDuplicateSwipe(): void
{
$operator = '操作员1';
$endoscope = '胃镜1';
// 第一次刷清洗
$result1 = $this->processor->swipe($operator, $endoscope, '清洗');
$this->assertSuccess($result1);
// 第二次刷清洗(重复刷卡)
$result2 = $this->processor->swipe($operator, $endoscope, '清洗');
// 应该被重复刷卡节点拦截
$this->assertNotNull($result2);
}
/**
* 测试读卡器未绑定
*/
public function testUnboundReader(): void
{
$context = $this->processor->createContextBuilder()
->endoscope('胃镜1')
->customReader('R999', '', '') // 未绑定的读卡器
->operator('操作员1')
->newProcess()
->build();
$engine = ProcessEngine::createStandard();
$result = $engine->execute($context);
// 读卡器未绑定应该在 FlowProcessor 层处理
// 这里主要测试 ProcessEngine 的行为
$this->assertNotNull($result);
}
/**
* 测试内镜卡未绑定
*/
public function testUnboundEndoscope(): void
{
$context = $this->processor->createContextBuilder()
->endoscope('未绑定卡')
->reader('清洗')
->operator('操作员1')
->newProcess()
->build();
$engine = ProcessEngine::createStandard();
$result = $engine->execute($context);
// 内镜未绑定应该触发错误
$this->assertNotNull($result);
}
}