158 lines
4.4 KiB
PHP
158 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace tests\flow\strategies;
|
|
|
|
use tests\flow\TestCase;
|
|
use app\flow\strategies\MorningWashStrategy;
|
|
use app\flow\nodes\MorningWashNode;
|
|
|
|
/**
|
|
* 晨洗判断策略单元测试
|
|
*/
|
|
class MorningWashStrategyTest extends TestCase
|
|
{
|
|
protected MorningWashStrategy $strategy;
|
|
protected MorningWashNode $node;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->strategy = new MorningWashStrategy();
|
|
$this->node = new MorningWashNode();
|
|
}
|
|
|
|
/**
|
|
* 测试不需要晨洗模式
|
|
*/
|
|
public function testNoneMode(): void
|
|
{
|
|
$strategy = new MorningWashStrategy(['mode' => 'none']);
|
|
|
|
$context = $this->createContext([
|
|
'todayWashRecords' => 0,
|
|
]);
|
|
|
|
$result = $strategy->execute($context, $this->node);
|
|
|
|
$this->assertFalse($result->needMorningWash);
|
|
$this->assertTrue($result->morningWashed);
|
|
}
|
|
|
|
/**
|
|
* 测试所有镜子需要晨洗模式
|
|
*/
|
|
public function testAllMode(): void
|
|
{
|
|
$strategy = new MorningWashStrategy(['mode' => 'all']);
|
|
|
|
$context = $this->createContext([
|
|
'todayWashRecords' => 5, // 已有记录
|
|
]);
|
|
|
|
$result = $strategy->execute($context, $this->node);
|
|
|
|
$this->assertTrue($result->needMorningWash);
|
|
}
|
|
|
|
/**
|
|
* 测试每天第一次需要晨洗模式
|
|
*/
|
|
public function testDailyFirstModeWithNoRecords(): void
|
|
{
|
|
$strategy = new MorningWashStrategy(['mode' => 'daily_first']);
|
|
|
|
$context = $this->createContext([
|
|
'todayWashRecords' => 0, // 今天没有记录
|
|
]);
|
|
|
|
$result = $strategy->execute($context, $this->node);
|
|
|
|
$this->assertTrue($result->needMorningWash);
|
|
}
|
|
|
|
/**
|
|
* 测试每天第一次需要晨洗模式(已有记录)
|
|
*/
|
|
public function testDailyFirstModeWithRecords(): void
|
|
{
|
|
$strategy = new MorningWashStrategy(['mode' => 'daily_first']);
|
|
|
|
$context = $this->createContext([
|
|
'todayWashRecords' => 3, // 今天已有记录
|
|
]);
|
|
|
|
$result = $strategy->execute($context, $this->node);
|
|
|
|
$this->assertFalse($result->needMorningWash);
|
|
}
|
|
|
|
/**
|
|
* 测试特定类型镜子需要晨洗
|
|
*/
|
|
public function testSpecificTypesMode(): void
|
|
{
|
|
$strategy = new MorningWashStrategy([
|
|
'mode' => 'specific_types',
|
|
'specific_types' => ['胃镜', '十二指肠镜'],
|
|
]);
|
|
|
|
// 胃镜需要晨洗
|
|
$context1 = $this->createContext([
|
|
'endoscopeType' => '胃镜',
|
|
]);
|
|
$result1 = $strategy->execute($context1, $this->node);
|
|
$this->assertTrue($result1->needMorningWash);
|
|
|
|
// 肠镜不需要晨洗
|
|
$context2 = $this->createContext([
|
|
'endoscopeType' => '肠镜',
|
|
]);
|
|
$result2 = $strategy->execute($context2, $this->node);
|
|
$this->assertFalse($result2->needMorningWash);
|
|
}
|
|
|
|
/**
|
|
* 测试存储时间模式(义乌模式)
|
|
*/
|
|
public function testStorageTimeMode(): void
|
|
{
|
|
$strategy = new MorningWashStrategy([
|
|
'mode' => 'storage_time',
|
|
'storage_threshold' => 4,
|
|
]);
|
|
|
|
// 已取出,不需要晨洗
|
|
$context1 = $this->createContext([
|
|
'lastActionType' => '存储',
|
|
'lastProcessName' => '内镜取出',
|
|
]);
|
|
$result1 = $strategy->execute($context1, $this->node);
|
|
$this->assertFalse($result1->needMorningWash);
|
|
|
|
// 存储超过4小时,需要晨洗
|
|
$context2 = $this->createContext([
|
|
'lastActionType' => '存储',
|
|
'lastProcessName' => '内镜放入',
|
|
'storageInTime' => date('Y-m-d H:i:s', time() - 5 * 3600), // 5小时前
|
|
]);
|
|
$result2 = $strategy->execute($context2, $this->node);
|
|
$this->assertTrue($result2->needMorningWash);
|
|
|
|
// 存储不足4小时,不需要晨洗
|
|
$context3 = $this->createContext([
|
|
'lastActionType' => '存储',
|
|
'lastProcessName' => '内镜放入',
|
|
'storageInTime' => date('Y-m-d H:i:s', time() - 2 * 3600), // 2小时前
|
|
]);
|
|
$result3 = $strategy->execute($context3, $this->node);
|
|
$this->assertFalse($result3->needMorningWash);
|
|
}
|
|
|
|
/**
|
|
* 测试策略名称
|
|
*/
|
|
public function testStrategyName(): void
|
|
{
|
|
$this->assertStringContainsString('晨洗判断策略', $this->strategy->getName());
|
|
}
|
|
}
|