ai-chore(config): 调整流程配置及改进测试代码
- 将 FLOW_USE_CUSTOM_PROCESS 从 true 改为 false,禁用自定义流程 - 在 BlockTest 测试用例中改用 setBlockMode 方法设置阻断模式 - 设置统一的错误处理,将错误转为异常抛出 - 重命名 BlockTest 测试文件路径,优化测试组织结构 - 更新 IDE php include paths,调整依赖包引用顺序 - 删除无用的 tests/flow/Test.php 测试文件 - 微调 start.php、webman、windows.php 配置或代码模块
This commit is contained in:
@@ -0,0 +1,174 @@
|
||||
<?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()->setBlockMode($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()->setBlockMode(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()->setBlockMode(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()->setBlockMode(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(), '时长达标应成功');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user