更新
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require dirname(__DIR__, 2) . '/vendor/autoload.php';
|
||||
|
||||
use app\adminapi\logic\tcm\PrescriptionOrderLogic;
|
||||
|
||||
$passed = 0;
|
||||
$assertSame = static function (mixed $expected, mixed $actual, string $message) use (&$passed): void {
|
||||
if ($expected !== $actual) {
|
||||
throw new RuntimeException(sprintf(
|
||||
"%s\nExpected: %s\nActual: %s",
|
||||
$message,
|
||||
var_export($expected, true),
|
||||
var_export($actual, true)
|
||||
));
|
||||
}
|
||||
++$passed;
|
||||
};
|
||||
|
||||
$resolveNames = new ReflectionMethod(PrescriptionOrderLogic::class, 'resolvePrescriptionNamesForExport');
|
||||
|
||||
$mainHerb = ['name' => '黄芪', 'dosage' => 10, 'formula_type' => '主方'];
|
||||
$auxHerb = ['name' => '龙骨', 'dosage' => 15, 'formula_type' => '辅方'];
|
||||
|
||||
$assertSame(
|
||||
['主方名', ''],
|
||||
$resolveNames->invoke(null, [
|
||||
'prescription_name' => '主方名',
|
||||
'herbs' => [$mainHerb],
|
||||
'aux_usage' => ['prescription_name' => '已删除的辅方名'],
|
||||
], [], []),
|
||||
'export must ignore a stale auxiliary prescription name when no auxiliary herbs exist'
|
||||
);
|
||||
|
||||
$assertSame(
|
||||
['主方名', ''],
|
||||
$resolveNames->invoke(null, [
|
||||
'prescription_name' => '主方名',
|
||||
'herbs' => json_encode([$mainHerb], JSON_UNESCAPED_UNICODE),
|
||||
'aux_usage' => json_encode(['library_name' => '已删除的处方库辅方名'], JSON_UNESCAPED_UNICODE),
|
||||
], [], []),
|
||||
'JSON-backed export data must ignore a stale auxiliary library name when no auxiliary herbs exist'
|
||||
);
|
||||
|
||||
$assertSame(
|
||||
['主方名', ''],
|
||||
$resolveNames->invoke(null, [
|
||||
'prescription_name' => '主方名',
|
||||
'creator_id' => 7,
|
||||
'herbs' => [$mainHerb],
|
||||
'aux_usage' => ['prescription_name' => '残留名称', 'usage_days' => 7],
|
||||
], [
|
||||
7 => [
|
||||
'辅方' => ['龙骨:15' => '不应命中的处方库辅方名'],
|
||||
],
|
||||
], [
|
||||
'辅方' => ['龙骨:15' => '不应命中的公开辅方名'],
|
||||
]),
|
||||
'stale auxiliary usage and library indexes must not imply that an auxiliary formula exists'
|
||||
);
|
||||
|
||||
$assertSame(
|
||||
['主方名', '持久化辅方名'],
|
||||
$resolveNames->invoke(null, [
|
||||
'prescription_name' => '主方名',
|
||||
'herbs' => [$mainHerb, $auxHerb],
|
||||
'aux_usage' => json_encode(['prescription_name' => '持久化辅方名'], JSON_UNESCAPED_UNICODE),
|
||||
], [], []),
|
||||
'export must keep the persisted auxiliary prescription name when auxiliary herbs exist'
|
||||
);
|
||||
|
||||
$assertSame(
|
||||
['主方名', '处方库辅方名'],
|
||||
$resolveNames->invoke(null, [
|
||||
'prescription_name' => '主方名',
|
||||
'creator_id' => 7,
|
||||
'herbs' => [$mainHerb, $auxHerb],
|
||||
], [
|
||||
7 => [
|
||||
'辅方' => ['龙骨:15' => '处方库辅方名'],
|
||||
],
|
||||
], []),
|
||||
'export must still resolve an auxiliary prescription name from the library when auxiliary herbs exist'
|
||||
);
|
||||
|
||||
fwrite(STDOUT, sprintf("Prescription order export name regression tests passed: %d\n", $passed));
|
||||
Reference in New Issue
Block a user