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
+202
View File
@@ -0,0 +1,202 @@
<?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);
}
}