e040fccba6
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext - 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示 - 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法 - 增加日志记录细节,便于调试策略执行中断时的错误信息 - 优化代码注释,提升代码可读性和维护性
203 lines
4.9 KiB
PHP
203 lines
4.9 KiB
PHP
<?php
|
||
|
||
namespace tests\flow\nodes;
|
||
|
||
use tests\flow\TestCase;
|
||
use app\flow\nodes\EndNode;
|
||
use app\flow\enum\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);
|
||
}
|
||
}
|