\Tests\FeatureDataDictConvenientTest

字典便捷操作四件套

被测对象:DataDictService(upsertItem/updateItem/deleteItem/getItem) 守护约定:业务代码按 (type_code, value) 定位字典项增删改查、不关心 id; 停用项不污染消费端缓存、层级字典按 parent_value 定位父级。

Summary

Methods
Properties
Constants
test_upsert_creates_then_updates_same_value()
test_update_item_by_value()
test_delete_item_is_idempotent()
test_upsert_tree_item_with_parent_value()
test_upsert_flat_type_rejects_parent()
test_upsert_unknown_type_throws()
test_include_disabled_does_not_pollute_consumer_cache()
No public properties found
No constants found
requireRedis()
buildCacheRegistry()
No protected properties found
N/A
makeType()
No private properties found
N/A

Methods

test_upsert_creates_then_updates_same_value()

test_upsert_creates_then_updates_same_value() : void

验证 upsert 同 value 先新增后覆盖(同 id 不新增行)。

test_update_item_by_value()

test_update_item_by_value() : void

验证按 (type_code, value) 更新项的 label 与 sort。

test_delete_item_is_idempotent()

test_delete_item_is_idempotent() : void

验证删除项幂等:删除不存在的项不报错。

test_upsert_tree_item_with_parent_value()

test_upsert_tree_item_with_parent_value() : void

验证树形字典 upsert 带 parent_value 时落父级 id。

test_upsert_flat_type_rejects_parent()

test_upsert_flat_type_rejects_parent() : void

验证扁平字典带 parent_value 被拒绝(不支持层级)。

test_upsert_unknown_type_throws()

test_upsert_unknown_type_throws() : void

验证 upsert 未知字典类型抛「字典类型不存在」。

test_include_disabled_does_not_pollute_consumer_cache()

test_include_disabled_does_not_pollute_consumer_cache() : void

验证停用项管理端可见、消费端剔除且不污染缓存词表。

requireRedis()

requireRedis() : void

Redis 依赖探针:直连 Redis 的测试(限流/会话/验证码)在无 Redis 环境(如 CI) 跳过而非失败——其余用例不受影响。CI 可设 TEST_REQUIRE_REDIS=1 强制模式: Redis 不可达即失败而非跳过,安全回归套件不允许静默消失。

buildCacheRegistry()

buildCacheRegistry(array  $items) : void

建缓存注册表最小 schema(td_sys_cache)并灌入注册项。

测试跑 sqlite :memory:,生产迁移含 PostgreSQL 专属 DDL 跑不通(DataScopeServiceTest 同因自建 schema); 而 CacheManager::registry() 现已从数据库表读取——凡走注册表的测试(remember/get/key/失效推导) 必须在 setUp 先调用本方法,否则注册表为空、remember 未登记名会走「自动登记」路径。

Parameters

array $items

makeType()

makeType(string  $code = 'gender', bool  $tree = false) : \App\Models\SysDictType

Parameters

string $code
bool $tree

Returns

\App\Models\SysDictType —