158 lines
4.2 KiB
PHP
158 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace tests\flow\nodes;
|
|
|
|
use tests\flow\TestCase;
|
|
use app\flow\nodes\MorningWashNode;
|
|
|
|
/**
|
|
* 晨洗节点单元测试
|
|
*/
|
|
class MorningWashNodeTest extends TestCase
|
|
{
|
|
protected MorningWashNode $node;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->node = new MorningWashNode();
|
|
}
|
|
|
|
/**
|
|
* 测试节点名称和编码
|
|
*/
|
|
public function testNodeIdentity(): void
|
|
{
|
|
$this->assertEquals('晨洗', $this->node->getName());
|
|
$this->assertEquals('晨洗', $this->node->getCode());
|
|
}
|
|
|
|
/**
|
|
* 测试可以处理消毒读卡器(晨洗模式)
|
|
*/
|
|
public function testCanHandleDisinfectReaderForMorningWash(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '消毒',
|
|
'currentStep' => '',
|
|
'needMorningWash' => true,
|
|
]);
|
|
|
|
$this->assertTrue($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试可以处理机洗读卡器(晨洗模式)
|
|
*/
|
|
public function testCanHandleMachineWashReaderForMorningWash(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '机洗',
|
|
'currentStep' => '',
|
|
'needMorningWash' => true,
|
|
]);
|
|
|
|
$this->assertTrue($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试不需要晨洗时不能处理
|
|
*/
|
|
public function testCannotHandleWhenNoNeed(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '晨洗',
|
|
'currentStep' => '',
|
|
'needMorningWash' => false,
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试非消毒/机洗读卡器不能处理晨洗
|
|
*/
|
|
public function testCannotHandleNonDisinfectMachineReader(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '清洗',
|
|
'currentStep' => '',
|
|
'needMorningWash' => true,
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试已完成晨洗后不能再次处理
|
|
*/
|
|
public function testCannotHandleWhenAlreadyWashed(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '晨洗',
|
|
'currentStep' => '晨洗',
|
|
'needMorningWash' => false,
|
|
'morningWashed' => true,
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试处理流程(消毒读卡器)
|
|
*/
|
|
public function testHandleProcessWithDisinfect(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '消毒',
|
|
'currentStep' => '',
|
|
'needMorningWash' => true,
|
|
'endoscopeId' => '', // 避免触发 DB 查询
|
|
]);
|
|
|
|
$result = $this->node->handle($context);
|
|
|
|
$this->assertSuccess($result);
|
|
$this->assertEquals('清洗', $result->currentStep); // 晨洗后进入清洗步骤
|
|
$this->assertTrue($result->morningWashed);
|
|
$this->assertEquals('手工洗(晨洗)', $result->processType);
|
|
}
|
|
|
|
/**
|
|
* 测试处理流程(机洗读卡器)
|
|
*/
|
|
public function testHandleProcessWithMachineWash(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '机洗',
|
|
'currentStep' => '',
|
|
'needMorningWash' => true,
|
|
'endoscopeId' => '', // 避免触发 DB 查询
|
|
]);
|
|
|
|
$result = $this->node->handle($context);
|
|
|
|
$this->assertSuccess($result);
|
|
$this->assertEquals('清洗', $result->currentStep);
|
|
$this->assertTrue($result->morningWashed);
|
|
$this->assertEquals('机洗(晨洗)', $result->processType);
|
|
}
|
|
|
|
/**
|
|
* 测试生成批次号
|
|
*/
|
|
public function testGenerateBatchNo(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '消毒',
|
|
'currentStep' => '',
|
|
'needMorningWash' => true,
|
|
'endoscopeId' => '', // 避免触发 DB 查询
|
|
]);
|
|
|
|
$this->node->handle($context);
|
|
|
|
$this->assertNotEmpty($context->batchNo);
|
|
$this->assertTrue($context->needDatabaseOperation);
|
|
}
|
|
}
|