feat: 实现TCP Server

This commit is contained in:
zimoyin
2026-03-02 21:59:43 +08:00
parent 043306819b
commit a79dfae57d
144 changed files with 15785 additions and 140 deletions
+158
View File
@@ -0,0 +1,158 @@
<?php
namespace tests\flow\nodes;
use tests\flow\TestCase;
use app\flow\nodes\DryNode;
use app\flow\DbOperationType;
/**
* 干燥节点单元测试
*/
class DryNodeTest extends TestCase
{
protected DryNode $node;
protected function setUp(): void
{
$this->node = new DryNode();
}
/**
* 测试节点名称和编码
*/
public function testNodeIdentity(): void
{
$this->assertEquals('干燥', $this->node->getName());
$this->assertEquals('干燥', $this->node->getCode());
}
/**
* 测试终末漂洗后可以刷干燥
*/
public function testCanHandleAfterFinalRinse(): void
{
$context = $this->createContext([
'readerType' => '干燥',
'currentStep' => '终末漂洗',
]);
$this->assertTrue($this->node->canHandle($context));
}
/**
* 测试消毒后可以直接刷干燥(跳过终末漂洗)
*/
public function testCanHandleAfterDisinfect(): 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 testCannotHandleNonDryReader(): 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' => '终末漂洗',
]);
$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);
}
/**
* 测试保持现有批次号
*/
public function testKeepExistingBatchNo(): void
{
$context = $this->createContext([
'readerType' => '干燥',
'currentStep' => '终末漂洗',
'batchNo' => '202603031200000000010001',
]);
$this->node->handle($context);
$this->assertEquals('202603031200000000010001', $context->batchNo);
}
}