Files
tcpserver-flow/tests/flow/nodes/MachineWashNodeTest.php
T
2026-03-08 22:58:56 +08:00

197 lines
4.7 KiB
PHP

<?php
namespace tests\flow\nodes;
use tests\flow\TestCase;
use app\flow\nodes\MachineWashNode;
use app\flow\DbOperationType;
/**
* 机洗节点单元测试
*/
class MachineWashNodeTest extends TestCase
{
protected MachineWashNode $node;
protected function setUp(): void
{
$this->node = new MachineWashNode();
}
/**
* 测试节点名称和编码
*/
public function testNodeIdentity(): void
{
$this->assertEquals('机洗', $this->node->getName());
$this->assertEquals('机洗', $this->node->getCode());
}
/**
* 测试清洗后可以刷机洗
*/
public function testCanHandleAfterWash(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '清洗',
]);
$this->assertTrue($this->node->canHandle($context));
}
/**
* 测试漂洗后可以刷机洗
*/
public function testCanHandleAfterRinse(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '漂洗',
]);
$this->assertTrue($this->node->canHandle($context));
}
/**
* 测试消毒后可以刷机洗
*/
public function testCanHandleAfterDisinfect(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '消毒',
]);
$this->assertTrue($this->node->canHandle($context));
}
/**
* 测试步骤为空时可以刷机洗(新流程开始)
*/
public function testCanHandleWithEmptyStep(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '',
]);
$this->assertTrue($this->node->canHandle($context));
}
/**
* 测试结束后可以刷机洗
*/
public function testCanHandleAfterEnd(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '结束',
]);
$this->assertTrue($this->node->canHandle($context));
}
/**
* 测试内镜取出后可以刷机洗
*/
public function testCanHandleAfterEndoscopeOut(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '内镜取出',
]);
$this->assertTrue($this->node->canHandle($context));
}
/**
* 测试非机洗读卡器不能处理
*/
public function testCannotHandleNonMachineWashReader(): void
{
$context = $this->createContext([
'readerType' => '清洗',
'currentStep' => '清洗',
]);
$this->assertFalse($this->node->canHandle($context));
}
/**
* 测试终末漂洗后不能刷机洗
*/
public function testCannotHandleAfterFinalRinse(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '终末漂洗',
]);
$this->assertFalse($this->node->canHandle($context));
}
/**
* 测试干燥后不能刷机洗
*/
public function testCannotHandleAfterDry(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '干燥',
]);
$this->assertFalse($this->node->canHandle($context));
}
/**
* 测试处理流程
*/
public function testHandleProcess(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '清洗',
'batchNo' => 'BATCH001',
]);
$result = $this->node->handle($context);
$this->assertSuccess($result);
$this->assertStep($result, '机洗');
$this->assertEquals('机洗', $result->processType);
$this->assertNotNull($result->getStepLastTime('机洗'));
}
/**
* 测试数据库操作标记
*/
public function testDatabaseOperationFlags(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '清洗',
]);
$this->node->handle($context);
$this->assertTrue($context->needDatabaseOperation);
$this->assertEquals(DbOperationType::INSERT, $context->dbOperation);
}
/**
* 测试 WebSocket 通知标记
*/
public function testWebSocketNotifyFlag(): void
{
$context = $this->createContext([
'readerType' => '机洗',
'currentStep' => '清洗',
]);
$this->node->handle($context);
$this->assertTrue($context->needWebSocketNotify);
}
}