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\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);
|
|
}
|
|
}
|