| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- <?php
- namespace App\Module\AppGame\Tests;
- /**
- * 测试配置类
- *
- * 集中管理所有测试用的环境变量和配置,方便编排测试
- */
- class TestConfig
- {
- /**
- * 测试用户配置
- */
- public const TEST_USER = [
- 'user_id' => 1,
- 'password' => 'test123456',
- 'username' => 'test_user'
- ];
- /**
- * 灾害去除测试配置
- */
- public const DISASTER_REMOVAL_TEST = [
- // 除虫测试配置
- 'pesticide' => [
- 'land_id' => 1, // 测试土地ID(需要有虫害的土地)
- 'item_id' => 101, // 除虫剂物品ID
- 'disaster_type' => 2, // 虫害类型
- 'expected_success_rate' => 80 // 预期成功率
- ],
-
- // 除草测试配置
- 'weedicide' => [
- 'land_id' => 2, // 测试土地ID(需要有杂草的土地)
- 'item_id' => 102, // 除草剂物品ID
- 'disaster_type' => 3, // 杂草类型
- 'expected_success_rate' => 75 // 预期成功率
- ],
-
- // 浇水测试配置
- 'watering' => [
- 'land_id' => 3, // 测试土地ID(需要有干旱的土地)
- 'item_id' => 103, // 浇水道具物品ID
- 'disaster_type' => 1, // 干旱类型
- 'expected_success_rate' => 90 // 预期成功率
- ]
- ];
- /**
- * 测试物品配置
- */
- public const TEST_ITEMS = [
- // 除虫剂
- 'pesticide' => [
- 'item_id' => 101,
- 'name' => '高效除虫剂',
- 'numeric_attributes' => [
- 'fram_pesticide_rate' => 80 // 80%成功率
- ]
- ],
-
- // 除草剂
- 'weedicide' => [
- 'item_id' => 102,
- 'name' => '强力除草剂',
- 'numeric_attributes' => [
- 'fram_weedicide_rate' => 75 // 75%成功率
- ]
- ],
-
- // 浇水道具
- 'watering_tool' => [
- 'item_id' => 103,
- 'name' => '自动洒水器',
- 'numeric_attributes' => [
- 'fram_drought_rate' => 90 // 90%成功率
- ]
- ],
-
- // 无效物品(用于测试失败情况)
- 'invalid_item' => [
- 'item_id' => 999,
- 'name' => '无效物品',
- 'numeric_attributes' => []
- ]
- ];
- /**
- * 测试土地配置
- */
- public const TEST_LANDS = [
- // 有虫害的土地
- 'pest_land' => [
- 'land_id' => 1,
- 'user_id' => 1,
- 'disaster_type' => 2, // 虫害
- 'crop_id' => 1,
- 'growth_stage' => 2
- ],
-
- // 有杂草的土地
- 'weed_land' => [
- 'land_id' => 2,
- 'user_id' => 1,
- 'disaster_type' => 3, // 杂草
- 'crop_id' => 2,
- 'growth_stage' => 3
- ],
-
- // 有干旱的土地
- 'drought_land' => [
- 'land_id' => 3,
- 'user_id' => 1,
- 'disaster_type' => 1, // 干旱
- 'crop_id' => 3,
- 'growth_stage' => 1
- ],
-
- // 无灾害的土地(用于测试失败情况)
- 'normal_land' => [
- 'land_id' => 4,
- 'user_id' => 1,
- 'disaster_type' => 0, // 无灾害
- 'crop_id' => 4,
- 'growth_stage' => 2
- ],
-
- // 其他用户的土地(用于测试权限)
- 'other_user_land' => [
- 'land_id' => 5,
- 'user_id' => 2, // 不同用户
- 'disaster_type' => 2,
- 'crop_id' => 5,
- 'growth_stage' => 1
- ]
- ];
- /**
- * 测试场景配置
- */
- public const TEST_SCENARIOS = [
- // 成功场景
- 'success_scenarios' => [
- 'pesticide_success' => [
- 'description' => '除虫成功测试',
- 'user_id' => 1,
- 'land_id' => 1,
- 'item_id' => 101,
- 'expected_result' => 'success'
- ],
- 'weedicide_success' => [
- 'description' => '除草成功测试',
- 'user_id' => 1,
- 'land_id' => 2,
- 'item_id' => 102,
- 'expected_result' => 'success'
- ],
- 'watering_success' => [
- 'description' => '浇水成功测试',
- 'user_id' => 1,
- 'land_id' => 3,
- 'item_id' => 103,
- 'expected_result' => 'success'
- ]
- ],
-
- // 失败场景
- 'failure_scenarios' => [
- 'invalid_item' => [
- 'description' => '使用无效物品测试',
- 'user_id' => 1,
- 'land_id' => 1,
- 'item_id' => 999,
- 'expected_error' => '不是除虫物品'
- ],
- 'no_permission' => [
- 'description' => '无权限访问土地测试',
- 'user_id' => 1,
- 'land_id' => 5, // 其他用户的土地
- 'item_id' => 101,
- 'expected_error' => '土地不存在或不属于当前用户'
- ],
- 'no_disaster' => [
- 'description' => '土地无对应灾害测试',
- 'user_id' => 1,
- 'land_id' => 4, // 无灾害的土地
- 'item_id' => 101,
- 'expected_error' => '灾害清理失败'
- ]
- ]
- ];
- /**
- * 获取测试用户ID
- */
- public static function getTestUserId(): int
- {
- return self::TEST_USER['user_id'];
- }
- /**
- * 获取测试用户密码
- */
- public static function getTestUserPassword(): string
- {
- return self::TEST_USER['password'];
- }
- /**
- * 获取除虫测试配置
- */
- public static function getPesticideTestConfig(): array
- {
- return self::DISASTER_REMOVAL_TEST['pesticide'];
- }
- /**
- * 获取除草测试配置
- */
- public static function getWeedicideTestConfig(): array
- {
- return self::DISASTER_REMOVAL_TEST['weedicide'];
- }
- /**
- * 获取浇水测试配置
- */
- public static function getWateringTestConfig(): array
- {
- return self::DISASTER_REMOVAL_TEST['watering'];
- }
- /**
- * 获取测试物品配置
- */
- public static function getTestItem(string $type): array
- {
- return self::TEST_ITEMS[$type] ?? [];
- }
- /**
- * 获取测试土地配置
- */
- public static function getTestLand(string $type): array
- {
- return self::TEST_LANDS[$type] ?? [];
- }
- /**
- * 获取测试场景配置
- */
- public static function getTestScenario(string $category, string $scenario): array
- {
- return self::TEST_SCENARIOS[$category][$scenario] ?? [];
- }
- }
|