e040fccba6
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext - 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示 - 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法 - 增加日志记录细节,便于调试策略执行中断时的错误信息 - 优化代码注释,提升代码可读性和维护性
164 lines
3.9 KiB
PHP
164 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace tests\flow\nodes;
|
|
|
|
use tests\flow\TestCase;
|
|
use app\flow\nodes\RinseNode;
|
|
use app\flow\enum\DbOperationType;
|
|
|
|
/**
|
|
* 漂洗节点单元测试
|
|
*/
|
|
class RinseNodeTest extends TestCase
|
|
{
|
|
protected RinseNode $node;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->node = new RinseNode();
|
|
// 确保每个测试时节点都是启用状态
|
|
$this->node->setEnabled(true);
|
|
}
|
|
|
|
/**
|
|
* 测试节点名称和编码
|
|
*/
|
|
public function testNodeIdentity(): void
|
|
{
|
|
$this->assertEquals('漂洗', $this->node->getName());
|
|
$this->assertEquals('漂洗', $this->node->getCode());
|
|
}
|
|
|
|
/**
|
|
* 测试清洗后可以刷漂洗
|
|
*/
|
|
public function testCanHandleAfterWash(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '漂洗',
|
|
'currentStep' => '清洗',
|
|
]);
|
|
|
|
$this->assertTrue($this->node->canHandle($context));
|
|
}
|
|
|
|
/**
|
|
* 测试非漂洗读卡器不能处理
|
|
*/
|
|
public function testCannotHandleNonRinseReader(): 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 testCannotHandleWithEmptyStep(): 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 testHandleProcess(): void
|
|
{
|
|
$context = $this->createContext([
|
|
'readerType' => '漂洗',
|
|
'currentStep' => '清洗',
|
|
'batchNo' => 'BATCH001',
|
|
]);
|
|
|
|
$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 testDisabledNodeSkips(): void
|
|
{
|
|
$this->node->setEnabled(false);
|
|
|
|
$context = $this->createContext([
|
|
'readerType' => '漂洗',
|
|
'currentStep' => '清洗',
|
|
]);
|
|
|
|
$result = $this->node->handle($context);
|
|
|
|
// 被禁用,currentStep 不应该变为漂洗
|
|
$this->assertEquals('清洗', $result->currentStep);
|
|
}
|
|
}
|