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

203 lines
4.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace tests\flow\nodes;
use tests\flow\TestCase;
use app\flow\nodes\EndNode;
use app\flow\DbOperationType;
/**
* 结束节点单元测试
*/
class EndNodeTest extends TestCase
{
protected EndNode $node;
protected function setUp(): void
{
$this->node = new EndNode();
}
/**
* 测试节点名称和编码
*/
public function testNodeIdentity(): void
{
$this->assertEquals('结束', $this->node->getName());
$this->assertEquals('结束', $this->node->getCode());
}
/**
* 测试干燥后可以刷结束
*/
public function testCanHandleAfterDry(): 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 testCanHandleAfterFinalRinse(): void
{
$context = $this->createContext([
'readerType' => '结束',
'currentStep' => '终末漂洗',
]);
$this->assertTrue($this->node->canHandle($context));
}
/**
* 测试机洗后可以刷结束
*/
public function testCanHandleAfterMachineWash(): void
{
$context = $this->createContext([
'readerType' => '结束',
'currentStep' => '机洗',
]);
$this->assertTrue($this->node->canHandle($context));
}
/**
* 测试非结束读卡器不能处理
*/
public function testCannotHandleNonEndReader(): void
{
$context = $this->createContext([
'readerType' => '清洗',
'currentStep' => '干燥',
]);
$this->assertFalse($this->node->canHandle($context));
}
/**
* 测试清洗后不能直接刷结束
*/
public function testCannotHandleAfterWash(): void
{
$context = $this->createContext([
'readerType' => '结束',
'currentStep' => '清洗',
]);
$this->assertFalse($this->node->canHandle($context));
}
/**
* 测试漂洗后不能直接刷结束
*/
public function testCannotHandleAfterRinse(): void
{
$context = $this->createContext([
'readerType' => '结束',
'currentStep' => '漂洗',
]);
$this->assertFalse($this->node->canHandle($context));
}
/**
* 测试空步骤不能刷结束
*/
public function testCannotHandleWithEmptyStep(): void
{
$context = $this->createContext([
'readerType' => '结束',
'currentStep' => '',
]);
$this->assertFalse($this->node->canHandle($context));
}
/**
* 测试处理流程
*/
public function testHandleProcess(): void
{
$context = $this->createContext([
'readerType' => '结束',
'currentStep' => '干燥',
'batchNo' => 'BATCH001',
'actionStartTime' => date('Y-m-d H:i:s', time() - 600),
]);
$result = $this->node->handle($context);
$this->assertSuccess($result);
$this->assertStep($result, '结束');
$this->assertNotEmpty($result->actionEndTime);
}
/**
* 测试数据库操作标记(update 而非 insert
*/
public function testDatabaseOperationIsUpdate(): void
{
$context = $this->createContext([
'readerType' => '结束',
'currentStep' => '干燥',
'batchNo' => 'BATCH001',
]);
$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);
}
/**
* 测试 actionEndTime 被设置
*/
public function testActionEndTimeIsSet(): void
{
$context = $this->createContext([
'readerType' => '结束',
'currentStep' => '干燥',
]);
$before = date('Y-m-d H:i:s');
$this->node->handle($context);
$after = date('Y-m-d H:i:s');
$this->assertGreaterThanOrEqual($before, $context->actionEndTime);
$this->assertLessThanOrEqual($after, $context->actionEndTime);
}
}