\Tests\UnitModelRelationTest

模型关系完整性契约

被测对象:全库 21 个业务模型的全部 Eloquent 关系定义 守护约定:关系类型、目标模型、外键列、多对多 pivot 表与两端 pivot 键一一断言; 新增/修改关系必须同步本契约,防止外键写错、方向缺失或目标模型漂移。

Summary

Methods
Properties
Constants
test_user_relations()
test_role_relations()
test_menu_relations()
test_permission_relations()
test_company_relations()
test_dept_relations()
test_post_relations()
test_binding_table_relations()
test_file_relations()
test_template_relations()
test_region_relations()
test_dict_relations()
test_config_relations()
No public properties found
No constants found
requireRedis()
buildCacheRegistry()
No protected properties found
N/A
relation()
assertHasMany()
assertBelongsTo()
assertBelongsToMany()
No private properties found
N/A

Methods

test_user_relations()

test_user_relations() : void

验证 SysUser 的九类关系(角色/岗位/范围/个人权限/任职/负责人/法人/文件/模板版本)。

test_role_relations()

test_role_relations() : void

验证 SysRole 的菜单/权限/用户三类多对多关系。

test_menu_relations()

test_menu_relations() : void

验证 SysMenu 的父子树、权限与角色关系。

test_permission_relations()

test_permission_relations() : void

验证 SysPermission 的菜单/父子树/角色/用户授权关系。

test_company_relations()

test_company_relations() : void

验证 SysCompany 的法人/地区/部门/岗位范围/用户范围关系。

test_dept_relations()

test_dept_relations() : void

验证 SysDept 的公司/负责人/地区/岗位范围/用户范围/岗位/任职关系。

test_post_relations()

test_post_relations() : void

验证 SysPost 的部门/岗位范围/任职用户关系。

test_binding_table_relations()

test_binding_table_relations() : void

验证任职/个人范围/岗位范围/个人授权四张绑定表的关系。

test_file_relations()

test_file_relations() : void

验证 SysFile 与 SysFileFolder 的所有者/目录/父子树关系。

test_template_relations()

test_template_relations() : void

验证 SysTemplate 与 SysTemplateVersion 的版本/创建者关系。

test_region_relations()

test_region_relations() : void

验证 SysRegion 的父子树与公司/部门挂靠关系。

test_dict_relations()

test_dict_relations() : void

验证 SysDictType 与 SysDictData 的数据/父级/子级关系。

test_config_relations()

test_config_relations() : void

验证 SysConfigDefinition 与 SysConfigValue 的定义/值关系。

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

relation()

relation(object  $model, string  $method) : object

断言关系方法存在并返回关系对象

Parameters

object $model
string $method

Returns

object —

assertHasMany()

assertHasMany(object  $model, string  $method, string  $related, string  $fk) : void

断言 HasMany 关系类型、目标模型与外键

Parameters

object $model
string $method
string $related
string $fk

assertBelongsTo()

assertBelongsTo(object  $model, string  $method, string  $related, string  $fk) : void

断言 BelongsTo 关系类型、目标模型与外键

Parameters

object $model
string $method
string $related
string $fk

assertBelongsToMany()

assertBelongsToMany(object  $model, string  $method, string  $related, string  $pivot, string  $fkPivot, string  $relatedPivot) : void

断言 BelongsToMany 关系类型、目标模型、pivot 表与两端 pivot 键

Parameters

object $model
string $method
string $related
string $pivot
string $fkPivot
string $relatedPivot