184 lines
6.1 KiB
PHP
184 lines
6.1 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()->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秒)
|
|
// 关键:设置 previousAction 和 processType 使得时间验证策略生效
|
|
$context = $this->processor->createContextBuilder()
|
|
->endoscope('胃镜1')
|
|
->reader('漂洗')
|
|
->operator('操作员1')
|
|
->currentStep('清洗')
|
|
->setPreviousAction('清洗') // 上一步也是清洗,表示重复刷同一步骤
|
|
->processType('手工洗') // 必须设置流程类型,否则 hasStep 返回 false
|
|
->setDuration(5) // 只有5秒,时间不足
|
|
->batchNo(date('Ymd') . '010001')
|
|
->build();
|
|
|
|
$engine = ProcessEngine::createStandard();
|
|
$result = $engine->execute($context);
|
|
// 输出语音
|
|
Logger::info("测试时间验证策略阻断 - 阻断模式开启 success:{}",[$result->isSuccess()]);
|
|
Logger::info($result->getFullVoice());
|
|
// 阻断模式下,时间不足应该导致流程失败
|
|
$this->assertFalse($result->isSuccess(), '阻断模式下,时长不足应失败');
|
|
}
|
|
|
|
/**
|
|
* 测试时间验证策略 - 阻断模式关闭
|
|
*
|
|
* 当 blockMode=false 时,清洗时长不达标仍可继续,但应有提醒
|
|
*/
|
|
public function testTimeValidationWithBlockModeOff(): void
|
|
{
|
|
// 关闭阻断模式
|
|
Config::getInstance()->setBlockMode(false);
|
|
|
|
// 创建一个时间不足的场景
|
|
$context = $this->processor->createContextBuilder()
|
|
->endoscope('胃镜1')
|
|
->reader('漂洗')
|
|
->operator('操作员1')
|
|
->currentStep('清洗')
|
|
->setPreviousAction('清洗') // 设置 previousAction 使时间验证生效
|
|
->processType('手工洗') // 必须设置流程类型
|
|
->setDuration(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('清洗')
|
|
->setPreviousAction('清洗') // 设置 previousAction 使时间验证生效
|
|
->processType('手工洗') // 必须设置流程类型
|
|
->setDuration(120) // 120秒,时间充足
|
|
->batchNo(date('Ymd') . '010001')
|
|
->build();
|
|
|
|
$engine = ProcessEngine::createStandard();
|
|
$result = $engine->execute($context);
|
|
|
|
// 时长达标应该成功
|
|
$this->assertTrue($result->isSuccess(), '时长达标应成功');
|
|
}
|
|
}
|