216 lines
7.4 KiB
PHP
216 lines
7.4 KiB
PHP
<?php
|
|
|
|
namespace tests\flow\cases;
|
|
|
|
use app\flow\config\ProcessConfig;
|
|
use app\flow\ProcessEngine;
|
|
use tests\flow\TestCase;
|
|
use tests\flow\VirtualContextBuilder;
|
|
use tests\flow\VirtualityFlowProcessor;
|
|
|
|
/**
|
|
* 手工洗流程测试
|
|
*
|
|
* 覆盖场景:
|
|
* 1. 正常完整手工洗流程
|
|
* 2. 正常完整手工晨洗流程
|
|
*/
|
|
class ManualWashTest extends TestCase
|
|
{
|
|
private VirtualityFlowProcessor $processor;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->processor = VirtualityFlowProcessor::createStandard();
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
parent::tearDown();
|
|
$this->processor->reset();
|
|
}
|
|
|
|
// ==================== 1. 正常完整手工洗流程 ====================
|
|
|
|
/**
|
|
* 测试完整手工洗流程:清洗 -> 漂洗 -> 消毒 -> 终末漂洗 -> 干燥
|
|
*/
|
|
public function testCompleteManualWashProcess(): void
|
|
{
|
|
$operator = '操作员1';
|
|
$endoscope = '胃镜1';
|
|
|
|
// 步骤1:清洗
|
|
$result1 = $this->processor->swipe($operator, $endoscope, '清洗');
|
|
$this->assertSuccess($result1, '清洗步骤应成功');
|
|
$this->assertStep($result1, '清洗');
|
|
$this->assertNeedDatabaseOperation($result1);
|
|
$batchNo = $result1->getBatchNo();
|
|
$this->assertNotEmpty($batchNo, '应生成批次号');
|
|
|
|
// 步骤2:漂洗
|
|
$result2 = $this->processor->swipe($operator, $endoscope, '漂洗');
|
|
$this->assertSuccess($result2, '漂洗步骤应成功');
|
|
$this->assertStep($result2, '漂洗');
|
|
$this->assertBatchNoEquals($result2, $batchNo, '批次号应保持一致');
|
|
|
|
// 步骤3:消毒
|
|
$result3 = $this->processor->swipe($operator, $endoscope, '消毒');
|
|
$this->assertSuccess($result3, '消毒步骤应成功');
|
|
$this->assertStep($result3, '消毒');
|
|
$this->assertBatchNoEquals($result3, $batchNo, '批次号应保持一致');
|
|
|
|
// 步骤4:终末漂洗
|
|
$result4 = $this->processor->swipe($operator, $endoscope, '终末漂洗');
|
|
$this->assertSuccess($result4, '终末漂洗步骤应成功');
|
|
$this->assertStep($result4, '终末漂洗');
|
|
$this->assertBatchNoEquals($result4, $batchNo, '批次号应保持一致');
|
|
|
|
// 步骤5:干燥
|
|
$result5 = $this->processor->swipe($operator, $endoscope, '干燥');
|
|
$this->assertSuccess($result5, '干燥步骤应成功');
|
|
$this->assertStep($result5, '干燥');
|
|
$this->assertBatchNoEquals($result5, $batchNo, '批次号应保持一致');
|
|
|
|
// 验证最终步骤成功
|
|
$this->assertTrue($result5->isSuccess(), '干燥步骤 isSuccess() 应为 true');
|
|
}
|
|
|
|
/**
|
|
* 测试使用便捷方法执行完整手工洗流程
|
|
*/
|
|
public function testCompleteManualWashProcessUsingHelper(): void
|
|
{
|
|
$results = $this->processor->executeFullManualWash('操作员1', '胃镜1');
|
|
|
|
$this->assertCount(5, $results, '应有5个步骤结果');
|
|
|
|
foreach ($results as $step => $result) {
|
|
$this->assertSuccess($result, "{$step} 步骤应成功");
|
|
$this->assertStep($result, $step);
|
|
$this->assertTrue($result->isSuccess(), "{$step} isSuccess() 应为 true");
|
|
}
|
|
|
|
// 验证批次号一致性
|
|
$batchNo = $results['清洗']->getBatchNo();
|
|
foreach ($results as $step => $result) {
|
|
$this->assertBatchNoEquals($result, $batchNo, "{$step} 批次号应一致");
|
|
}
|
|
}
|
|
|
|
// ==================== 2. 正常完整手工晨洗流程 ====================
|
|
|
|
/**
|
|
* 测试晨洗判断 - 当天首次使用需要晨洗
|
|
*/
|
|
public function testMorningWashRequired(): void
|
|
{
|
|
// 创建需要晨洗的上下文
|
|
$context = $this->processor->createContextBuilder()
|
|
->endoscope('胃镜1')
|
|
->reader('清洗')
|
|
->operator('操作员1')
|
|
->needMorningWash(0) // 今天没有洗消记录
|
|
->newProcess()
|
|
->build();
|
|
|
|
// 执行流程
|
|
$engine = ProcessEngine::createStandard();
|
|
$result = $engine->execute($context);
|
|
|
|
// 晨洗策略应该生效
|
|
$this->assertNotNull($result);
|
|
}
|
|
|
|
/**
|
|
* 测试晨洗完成后的正常流程
|
|
*/
|
|
public function testManualWashAfterMorningWash(): void
|
|
{
|
|
$operator = '操作员1';
|
|
$endoscope = '胃镜1';
|
|
|
|
// 模拟晨洗已完成状态,执行正常流程
|
|
$this->processor->clearEndoscopeState($endoscope);
|
|
|
|
// 执行完整手工洗流程
|
|
$results = $this->processor->executeFullManualWash($operator, $endoscope);
|
|
|
|
// 验证所有步骤成功
|
|
foreach ($results as $step => $result) {
|
|
$this->assertSuccess($result, "{$step} 应成功");
|
|
$this->assertTrue($result->isSuccess(), "{$step} isSuccess() 应为 true");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 测试不同操作员接手流程
|
|
*/
|
|
public function testDifferentOperatorContinueProcess(): void
|
|
{
|
|
$endoscope = '胃镜1';
|
|
|
|
// 操作员1开始清洗
|
|
$result1 = $this->processor->swipe('操作员1', $endoscope, '清洗');
|
|
$this->assertSuccess($result1);
|
|
$batchNo = $result1->getBatchNo();
|
|
|
|
// 操作员2继续漂洗
|
|
$result2 = $this->processor->swipe('操作员2', $endoscope, '漂洗');
|
|
|
|
// 不同操作员应该可以继续流程
|
|
$this->assertSuccess($result2);
|
|
$this->assertBatchNoEquals($result2, $batchNo, '批次号应保持一致');
|
|
}
|
|
|
|
/**
|
|
* 测试流程完成后开始新流程
|
|
*/
|
|
public function testNewProcessAfterComplete(): void
|
|
{
|
|
$operator = '操作员1';
|
|
$endoscope = '胃镜1';
|
|
|
|
// 完成一个完整流程
|
|
$results = $this->processor->executeFullManualWash($operator, $endoscope);
|
|
$firstBatchNo = $results['清洗']->getBatchNo();
|
|
|
|
// 清除状态,开始新流程
|
|
$this->processor->clearEndoscopeState($endoscope);
|
|
|
|
// 开始新流程
|
|
$newResult = $this->processor->swipe($operator, $endoscope, '清洗');
|
|
|
|
// 应该成功,且批次号不同
|
|
$this->assertSuccess($newResult);
|
|
$this->assertNotEquals($firstBatchNo, $newResult->getBatchNo(), '新流程应有新批次号');
|
|
}
|
|
|
|
/**
|
|
* 不同内镜同时进行
|
|
*/
|
|
public function testConcurrentProcessIsolation(): void
|
|
{
|
|
$operator = '操作员1';
|
|
|
|
// 胃镜1开始清洗
|
|
$result1 = $this->processor->swipe($operator, '胃镜1', '清洗');
|
|
$this->assertSuccess($result1);
|
|
$batchNo1 = $result1->getBatchNo();
|
|
|
|
// 肠镜1也开始清洗
|
|
$result2 = $this->processor->swipe($operator, '肠镜1', '清洗');
|
|
$this->assertSuccess($result2);
|
|
$batchNo2 = $result2->getBatchNo();
|
|
|
|
// 两个内镜的批次号应该不同
|
|
$this->assertNotEquals($batchNo1, $batchNo2, '不同内镜应有不同批次号');
|
|
|
|
// 继续胃镜1的流程
|
|
$result3 = $this->processor->swipe($operator, '胃镜1', '漂洗');
|
|
$this->assertSuccess($result3);
|
|
$this->assertBatchNoEquals($result3, $batchNo1, '胃镜1批次号应保持不变');
|
|
}
|
|
}
|