TestConfig.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. namespace App\Module\AppGame\Tests;
  3. /**
  4. * 测试配置类
  5. *
  6. * 集中管理所有测试用的环境变量和配置,方便编排测试
  7. */
  8. class TestConfig
  9. {
  10. /**
  11. * 测试用户配置
  12. */
  13. public const TEST_USER = [
  14. 'user_id' => 1,
  15. 'password' => 'test123456',
  16. 'username' => 'test_user'
  17. ];
  18. /**
  19. * 灾害去除测试配置
  20. */
  21. public const DISASTER_REMOVAL_TEST = [
  22. // 除虫测试配置
  23. 'pesticide' => [
  24. 'land_id' => 1, // 测试土地ID(需要有虫害的土地)
  25. 'item_id' => 101, // 除虫剂物品ID
  26. 'disaster_type' => 2, // 虫害类型
  27. 'expected_success_rate' => 80 // 预期成功率
  28. ],
  29. // 除草测试配置
  30. 'weedicide' => [
  31. 'land_id' => 2, // 测试土地ID(需要有杂草的土地)
  32. 'item_id' => 102, // 除草剂物品ID
  33. 'disaster_type' => 3, // 杂草类型
  34. 'expected_success_rate' => 75 // 预期成功率
  35. ],
  36. // 浇水测试配置
  37. 'watering' => [
  38. 'land_id' => 3, // 测试土地ID(需要有干旱的土地)
  39. 'item_id' => 103, // 浇水道具物品ID
  40. 'disaster_type' => 1, // 干旱类型
  41. 'expected_success_rate' => 90 // 预期成功率
  42. ]
  43. ];
  44. /**
  45. * 测试物品配置
  46. */
  47. public const TEST_ITEMS = [
  48. // 除虫剂
  49. 'pesticide' => [
  50. 'item_id' => 101,
  51. 'name' => '高效除虫剂',
  52. 'numeric_attributes' => [
  53. 'fram_pesticide_rate' => 80 // 80%成功率
  54. ]
  55. ],
  56. // 除草剂
  57. 'weedicide' => [
  58. 'item_id' => 102,
  59. 'name' => '强力除草剂',
  60. 'numeric_attributes' => [
  61. 'fram_weedicide_rate' => 75 // 75%成功率
  62. ]
  63. ],
  64. // 浇水道具
  65. 'watering_tool' => [
  66. 'item_id' => 103,
  67. 'name' => '自动洒水器',
  68. 'numeric_attributes' => [
  69. 'fram_drought_rate' => 90 // 90%成功率
  70. ]
  71. ],
  72. // 无效物品(用于测试失败情况)
  73. 'invalid_item' => [
  74. 'item_id' => 999,
  75. 'name' => '无效物品',
  76. 'numeric_attributes' => []
  77. ]
  78. ];
  79. /**
  80. * 测试土地配置
  81. */
  82. public const TEST_LANDS = [
  83. // 有虫害的土地
  84. 'pest_land' => [
  85. 'land_id' => 1,
  86. 'user_id' => 1,
  87. 'disaster_type' => 2, // 虫害
  88. 'crop_id' => 1,
  89. 'growth_stage' => 2
  90. ],
  91. // 有杂草的土地
  92. 'weed_land' => [
  93. 'land_id' => 2,
  94. 'user_id' => 1,
  95. 'disaster_type' => 3, // 杂草
  96. 'crop_id' => 2,
  97. 'growth_stage' => 3
  98. ],
  99. // 有干旱的土地
  100. 'drought_land' => [
  101. 'land_id' => 3,
  102. 'user_id' => 1,
  103. 'disaster_type' => 1, // 干旱
  104. 'crop_id' => 3,
  105. 'growth_stage' => 1
  106. ],
  107. // 无灾害的土地(用于测试失败情况)
  108. 'normal_land' => [
  109. 'land_id' => 4,
  110. 'user_id' => 1,
  111. 'disaster_type' => 0, // 无灾害
  112. 'crop_id' => 4,
  113. 'growth_stage' => 2
  114. ],
  115. // 其他用户的土地(用于测试权限)
  116. 'other_user_land' => [
  117. 'land_id' => 5,
  118. 'user_id' => 2, // 不同用户
  119. 'disaster_type' => 2,
  120. 'crop_id' => 5,
  121. 'growth_stage' => 1
  122. ]
  123. ];
  124. /**
  125. * 测试场景配置
  126. */
  127. public const TEST_SCENARIOS = [
  128. // 成功场景
  129. 'success_scenarios' => [
  130. 'pesticide_success' => [
  131. 'description' => '除虫成功测试',
  132. 'user_id' => 1,
  133. 'land_id' => 1,
  134. 'item_id' => 101,
  135. 'expected_result' => 'success'
  136. ],
  137. 'weedicide_success' => [
  138. 'description' => '除草成功测试',
  139. 'user_id' => 1,
  140. 'land_id' => 2,
  141. 'item_id' => 102,
  142. 'expected_result' => 'success'
  143. ],
  144. 'watering_success' => [
  145. 'description' => '浇水成功测试',
  146. 'user_id' => 1,
  147. 'land_id' => 3,
  148. 'item_id' => 103,
  149. 'expected_result' => 'success'
  150. ]
  151. ],
  152. // 失败场景
  153. 'failure_scenarios' => [
  154. 'invalid_item' => [
  155. 'description' => '使用无效物品测试',
  156. 'user_id' => 1,
  157. 'land_id' => 1,
  158. 'item_id' => 999,
  159. 'expected_error' => '不是除虫物品'
  160. ],
  161. 'no_permission' => [
  162. 'description' => '无权限访问土地测试',
  163. 'user_id' => 1,
  164. 'land_id' => 5, // 其他用户的土地
  165. 'item_id' => 101,
  166. 'expected_error' => '土地不存在或不属于当前用户'
  167. ],
  168. 'no_disaster' => [
  169. 'description' => '土地无对应灾害测试',
  170. 'user_id' => 1,
  171. 'land_id' => 4, // 无灾害的土地
  172. 'item_id' => 101,
  173. 'expected_error' => '灾害清理失败'
  174. ]
  175. ]
  176. ];
  177. /**
  178. * 获取测试用户ID
  179. */
  180. public static function getTestUserId(): int
  181. {
  182. return self::TEST_USER['user_id'];
  183. }
  184. /**
  185. * 获取测试用户密码
  186. */
  187. public static function getTestUserPassword(): string
  188. {
  189. return self::TEST_USER['password'];
  190. }
  191. /**
  192. * 获取除虫测试配置
  193. */
  194. public static function getPesticideTestConfig(): array
  195. {
  196. return self::DISASTER_REMOVAL_TEST['pesticide'];
  197. }
  198. /**
  199. * 获取除草测试配置
  200. */
  201. public static function getWeedicideTestConfig(): array
  202. {
  203. return self::DISASTER_REMOVAL_TEST['weedicide'];
  204. }
  205. /**
  206. * 获取浇水测试配置
  207. */
  208. public static function getWateringTestConfig(): array
  209. {
  210. return self::DISASTER_REMOVAL_TEST['watering'];
  211. }
  212. /**
  213. * 获取测试物品配置
  214. */
  215. public static function getTestItem(string $type): array
  216. {
  217. return self::TEST_ITEMS[$type] ?? [];
  218. }
  219. /**
  220. * 获取测试土地配置
  221. */
  222. public static function getTestLand(string $type): array
  223. {
  224. return self::TEST_LANDS[$type] ?? [];
  225. }
  226. /**
  227. * 获取测试场景配置
  228. */
  229. public static function getTestScenario(string $category, string $scenario): array
  230. {
  231. return self::TEST_SCENARIOS[$category][$scenario] ?? [];
  232. }
  233. }