143 lines
3.3 KiB
PHP
143 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace tests\flow\nodes;
|
|
|
|
use tests\flow\TestCase;
|
|
use app\flow\nodes\DisinfectNode;
|
|
use app\flow\DbOperationType;
|
|
|
|
/**
|
|
* 消毒节点单元测试
|
|
*/
|
|
class DisinfectNodeTest extends TestCase
|
|
{
|
|
protected DisinfectNode $node;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->node = new DisinfectNode();
|
|
}
|
|
|
|
/**
|
|
* 测试节点名称和编码
|
|
*/
|
|
public function testNodeIdentity(): void
|
|
{
|
|
$this->assertEquals('消毒', $this->node->getName());
|
|
$this->assertEquals('消毒', $this->node->getCode());
|
|
}
|
|
|
|
/**
|
|
* 测试漂洗后可以刷消毒
|
|
*/
|
|
public function testCanHandleAfterRinse(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '消毒',
|
|
'currentStep' => '漂洗',
|
|
]);
|
|
|
|
$this->assertTrue($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试终末漂洗后禁止刷消毒
|
|
*/
|
|
public function testCanHandleAfterFinalRinse(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '消毒',
|
|
'currentStep' => '终末漂洗',
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试清洗后禁止直接刷消毒
|
|
*/
|
|
public function testCanHandleAfterWash(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '消毒',
|
|
'currentStep' => '清洗',
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试不能处理非消毒读卡器
|
|
*/
|
|
public function testCannotHandleNonDisinfectReader(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '清洗',
|
|
'currentStep' => '漂洗',
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试消毒后不能立即刷消毒
|
|
*/
|
|
public function testCannotHandleAfterDisinfect(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '消毒',
|
|
'currentStep' => '消毒',
|
|
]);
|
|
|
|
$this->assertFalse($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试处理流程
|
|
*/
|
|
public function testHandleProcess(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '消毒',
|
|
'currentStep' => '漂洗',
|
|
]);
|
|
|
|
$result = $this->node->handle($context);
|
|
|
|
$this->assertSuccess($result);
|
|
$this->assertStep($result, '消毒');
|
|
$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);
|
|
}
|
|
}
|