e040fccba6
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext - 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示 - 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法 - 增加日志记录细节,便于调试策略执行中断时的错误信息 - 优化代码注释,提升代码可读性和维护性
149 lines
3.7 KiB
PHP
149 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace tests\flow\nodes;
|
|
|
|
use tests\flow\TestCase;
|
|
use app\flow\nodes\WashNode;
|
|
use app\flow\enum\DbOperationType;
|
|
|
|
/**
|
|
* 清洗节点单元测试
|
|
*/
|
|
class WashNodeTest extends TestCase
|
|
{
|
|
protected WashNode $node;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->node = new WashNode();
|
|
}
|
|
|
|
/**
|
|
* 测试节点名称和编码
|
|
*/
|
|
public function testNodeIdentity(): void
|
|
{
|
|
$this->assertEquals('清洗', $this->node->getName());
|
|
$this->assertEquals('清洗', $this->node->getCode());
|
|
}
|
|
|
|
/**
|
|
* 测试可以处理清洗读卡器
|
|
*/
|
|
public function testCanHandleWashReader(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '清洗',
|
|
'currentStep' => '',
|
|
'morningWashed' => true,
|
|
]);
|
|
|
|
$this->assertTrue($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试不能处理非清洗读卡器
|
|
*/
|
|
public function testCannotHandleNonWashReader(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '消毒',
|
|
'currentStep' => '',
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试新流程可以开始清洗
|
|
*/
|
|
public function testCanStartNewWashProcess(): void
|
|
{
|
|
$validSteps = ['', '结束', '内镜取出', '内镜放入', '测漏正常'];
|
|
|
|
foreach ($validSteps as $step) {
|
|
$context = $this->createContext([
|
|
'readerType' => '清洗',
|
|
'currentStep' => $step,
|
|
'morningWashed' => true,
|
|
]);
|
|
|
|
$this->assertTrue(
|
|
$this->node->canHandle($context),
|
|
"步骤 '{$step}' 应该可以开始清洗"
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 测试未完成晨洗不能开始清洗
|
|
*/
|
|
public function testCannotWashWithoutMorningWash(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '清洗',
|
|
'currentStep' => '',
|
|
'needMorningWash' => true,
|
|
'morningWashed' => false,
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试处理流程
|
|
*/
|
|
public function testHandleProcess(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '清洗',
|
|
'currentStep' => '',
|
|
'morningWashed' => true,
|
|
'endoscopeId' => '', // 避免触发 DB 查询
|
|
]);
|
|
|
|
$result = $this->node->handle($context);
|
|
|
|
$this->assertSuccess($result);
|
|
$this->assertStep($result, '清洗');
|
|
$this->assertEquals('手工洗', $result->processType);
|
|
$this->assertNotNull($result->getStepLastTime('清洗'));
|
|
}
|
|
|
|
/**
|
|
* 测试生成批次号
|
|
*/
|
|
public function testGenerateBatchNo(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '清洗',
|
|
'currentStep' => '',
|
|
'morningWashed' => true,
|
|
'endoscopeId' => '', // 避免触发 DB 查询
|
|
]);
|
|
|
|
$this->node->handle($context);
|
|
|
|
$this->assertNotEmpty($context->batchNo);
|
|
$this->assertTrue($context->needDatabaseOperation);
|
|
$this->assertEquals(DbOperationType::INSERT, $context->dbOperation);
|
|
}
|
|
|
|
/**
|
|
* 测试已有批次号不重新生成
|
|
*/
|
|
public function testKeepExistingBatchNo(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '清洗',
|
|
'currentStep' => '漂洗', // 已有流程
|
|
'batchNo' => 'EXISTING001',
|
|
'morningWashed' => true,
|
|
]);
|
|
|
|
$this->node->handle($context);
|
|
|
|
$this->assertEquals('EXISTING001', $context->batchNo);
|
|
}
|
|
}
|