|
|
@@ -0,0 +1,347 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Module\AppGame\Tests\Land;
|
|
|
+
|
|
|
+use App\Module\AppGame\Tests\TestConfig;
|
|
|
+use Tests\TestCase;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 灾害去除测试套件
|
|
|
+ *
|
|
|
+ * 集成所有灾害去除相关的测试,提供统一的测试入口和报告
|
|
|
+ */
|
|
|
+class DisasterRemovalTestSuite extends TestCase
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 测试结果统计
|
|
|
+ */
|
|
|
+ private array $testResults = [
|
|
|
+ 'total' => 0,
|
|
|
+ 'passed' => 0,
|
|
|
+ 'failed' => 0,
|
|
|
+ 'errors' => []
|
|
|
+ ];
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运行完整的灾害去除测试套件
|
|
|
+ */
|
|
|
+ public function testCompleteDisasterRemovalSuite()
|
|
|
+ {
|
|
|
+ $this->dumpSuiteStart();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 1. 运行除虫测试
|
|
|
+ $this->runPesticideTests();
|
|
|
+
|
|
|
+ // 2. 运行除草测试
|
|
|
+ $this->runWeedicideTests();
|
|
|
+
|
|
|
+ // 3. 运行浇水测试
|
|
|
+ $this->runWateringTests();
|
|
|
+
|
|
|
+ // 4. 运行集成测试
|
|
|
+ $this->runIntegrationTests();
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $this->recordError('测试套件执行异常', $e);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->dumpSuiteResults();
|
|
|
+ $this->dumpSuiteEnd();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运行除虫测试
|
|
|
+ */
|
|
|
+ private function runPesticideTests(): void
|
|
|
+ {
|
|
|
+ dump("=== 开始除虫测试模块 ===");
|
|
|
+
|
|
|
+ try {
|
|
|
+ $pesticideTest = new PesticideHandlerTest();
|
|
|
+ $pesticideTest->setUp();
|
|
|
+
|
|
|
+ // 基础功能测试
|
|
|
+ $this->runSingleTest('除虫成功测试', function() use ($pesticideTest) {
|
|
|
+ $pesticideTest->testPesticideSuccess();
|
|
|
+ });
|
|
|
+
|
|
|
+ $this->runSingleTest('无效物品除虫测试', function() use ($pesticideTest) {
|
|
|
+ $pesticideTest->testPesticideWithInvalidItem();
|
|
|
+ });
|
|
|
+
|
|
|
+ $this->runSingleTest('其他用户土地除虫测试', function() use ($pesticideTest) {
|
|
|
+ $pesticideTest->testPesticideOnOtherUserLand();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 概率测试
|
|
|
+ $this->runSingleTest('除虫概率机制测试', function() use ($pesticideTest) {
|
|
|
+ $pesticideTest->testPesticideProbability();
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $this->recordError('除虫测试模块', $e);
|
|
|
+ }
|
|
|
+
|
|
|
+ dump("=== 除虫测试模块完成 ===");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运行除草测试
|
|
|
+ */
|
|
|
+ private function runWeedicideTests(): void
|
|
|
+ {
|
|
|
+ dump("=== 开始除草测试模块 ===");
|
|
|
+
|
|
|
+ try {
|
|
|
+ $weedicideTest = new WeedicideHandlerTest();
|
|
|
+ $weedicideTest->setUp();
|
|
|
+
|
|
|
+ // 基础功能测试
|
|
|
+ $this->runSingleTest('除草成功测试', function() use ($weedicideTest) {
|
|
|
+ $weedicideTest->testWeedicideSuccess();
|
|
|
+ });
|
|
|
+
|
|
|
+ $this->runSingleTest('无效物品除草测试', function() use ($weedicideTest) {
|
|
|
+ $weedicideTest->testWeedicideWithInvalidItem();
|
|
|
+ });
|
|
|
+
|
|
|
+ $this->runSingleTest('错误物品类型除草测试', function() use ($weedicideTest) {
|
|
|
+ $weedicideTest->testWeedicideWithWrongItemType();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 概率测试
|
|
|
+ $this->runSingleTest('除草概率机制测试', function() use ($weedicideTest) {
|
|
|
+ $weedicideTest->testWeedicideProbability();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 并发测试
|
|
|
+ $this->runSingleTest('并发除草请求测试', function() use ($weedicideTest) {
|
|
|
+ $weedicideTest->testConcurrentWeedicideRequests();
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $this->recordError('除草测试模块', $e);
|
|
|
+ }
|
|
|
+
|
|
|
+ dump("=== 除草测试模块完成 ===");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运行浇水测试
|
|
|
+ */
|
|
|
+ private function runWateringTests(): void
|
|
|
+ {
|
|
|
+ dump("=== 开始浇水测试模块 ===");
|
|
|
+
|
|
|
+ try {
|
|
|
+ $wateringTest = new WateringHandlerTest();
|
|
|
+ $wateringTest->setUp();
|
|
|
+
|
|
|
+ // 基础功能测试
|
|
|
+ $this->runSingleTest('浇水成功测试', function() use ($wateringTest) {
|
|
|
+ $wateringTest->testWateringSuccess();
|
|
|
+ });
|
|
|
+
|
|
|
+ $this->runSingleTest('无效物品浇水测试', function() use ($wateringTest) {
|
|
|
+ $wateringTest->testWateringWithInvalidItem();
|
|
|
+ });
|
|
|
+
|
|
|
+ $this->runSingleTest('错误物品类型浇水测试', function() use ($wateringTest) {
|
|
|
+ $wateringTest->testWateringWithWrongItemType();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 概率测试
|
|
|
+ $this->runSingleTest('浇水概率机制测试', function() use ($wateringTest) {
|
|
|
+ $wateringTest->testWateringProbability();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 重复操作测试
|
|
|
+ $this->runSingleTest('重复浇水测试', function() use ($wateringTest) {
|
|
|
+ $wateringTest->testRepeatedWateringOnSameLand();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 性能测试
|
|
|
+ $this->runSingleTest('浇水性能测试', function() use ($wateringTest) {
|
|
|
+ $wateringTest->testWateringPerformance();
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $this->recordError('浇水测试模块', $e);
|
|
|
+ }
|
|
|
+
|
|
|
+ dump("=== 浇水测试模块完成 ===");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运行集成测试
|
|
|
+ */
|
|
|
+ private function runIntegrationTests(): void
|
|
|
+ {
|
|
|
+ dump("=== 开始集成测试模块 ===");
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 测试混合使用不同类型的灾害去除道具
|
|
|
+ $this->runSingleTest('混合灾害去除测试', function() {
|
|
|
+ $this->testMixedDisasterRemoval();
|
|
|
+ });
|
|
|
+
|
|
|
+ // 测试配置验证
|
|
|
+ $this->runSingleTest('测试配置验证', function() {
|
|
|
+ $this->testConfigValidation();
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $this->recordError('集成测试模块', $e);
|
|
|
+ }
|
|
|
+
|
|
|
+ dump("=== 集成测试模块完成 ===");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试混合灾害去除
|
|
|
+ */
|
|
|
+ private function testMixedDisasterRemoval(): void
|
|
|
+ {
|
|
|
+ dump("开始混合灾害去除测试");
|
|
|
+
|
|
|
+ // 依次测试不同类型的灾害去除
|
|
|
+ $scenarios = [
|
|
|
+ ['type' => 'pesticide', 'description' => '除虫'],
|
|
|
+ ['type' => 'weedicide', 'description' => '除草'],
|
|
|
+ ['type' => 'watering', 'description' => '浇水']
|
|
|
+ ];
|
|
|
+
|
|
|
+ foreach ($scenarios as $scenario) {
|
|
|
+ dump("测试 {$scenario['description']} 功能");
|
|
|
+
|
|
|
+ $config = TestConfig::getTestScenario('success_scenarios', $scenario['type'] . '_success');
|
|
|
+ if (!empty($config)) {
|
|
|
+ dump("配置: ", $config);
|
|
|
+ // 这里可以添加具体的测试逻辑
|
|
|
+ $this->assertTrue(true, "{$scenario['description']} 测试通过");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dump("混合灾害去除测试完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 测试配置验证
|
|
|
+ */
|
|
|
+ private function testConfigValidation(): void
|
|
|
+ {
|
|
|
+ dump("开始测试配置验证");
|
|
|
+
|
|
|
+ // 验证测试用户配置
|
|
|
+ $testUser = TestConfig::getTestUserId();
|
|
|
+ $this->assertGreaterThan(0, $testUser, '测试用户ID应该大于0');
|
|
|
+
|
|
|
+ // 验证灾害去除配置
|
|
|
+ $pesticideConfig = TestConfig::getPesticideTestConfig();
|
|
|
+ $this->assertArrayHasKey('land_id', $pesticideConfig, '除虫配置应包含land_id');
|
|
|
+ $this->assertArrayHasKey('item_id', $pesticideConfig, '除虫配置应包含item_id');
|
|
|
+
|
|
|
+ $weedicideConfig = TestConfig::getWeedicideTestConfig();
|
|
|
+ $this->assertArrayHasKey('land_id', $weedicideConfig, '除草配置应包含land_id');
|
|
|
+ $this->assertArrayHasKey('item_id', $weedicideConfig, '除草配置应包含item_id');
|
|
|
+
|
|
|
+ $wateringConfig = TestConfig::getWateringTestConfig();
|
|
|
+ $this->assertArrayHasKey('land_id', $wateringConfig, '浇水配置应包含land_id');
|
|
|
+ $this->assertArrayHasKey('item_id', $wateringConfig, '浇水配置应包含item_id');
|
|
|
+
|
|
|
+ // 验证测试物品配置
|
|
|
+ $pesticideItem = TestConfig::getTestItem('pesticide');
|
|
|
+ $this->assertArrayHasKey('item_id', $pesticideItem, '除虫剂配置应包含item_id');
|
|
|
+
|
|
|
+ dump("测试配置验证完成");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 运行单个测试
|
|
|
+ */
|
|
|
+ private function runSingleTest(string $testName, callable $testFunction): void
|
|
|
+ {
|
|
|
+ $this->testResults['total']++;
|
|
|
+
|
|
|
+ try {
|
|
|
+ dump("开始测试: {$testName}");
|
|
|
+ $testFunction();
|
|
|
+ $this->testResults['passed']++;
|
|
|
+ dump("测试通过: {$testName}");
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ $this->testResults['failed']++;
|
|
|
+ $this->recordError($testName, $e);
|
|
|
+ dump("测试失败: {$testName} - " . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 记录错误
|
|
|
+ */
|
|
|
+ private function recordError(string $testName, \Exception $e): void
|
|
|
+ {
|
|
|
+ $this->testResults['errors'][] = [
|
|
|
+ 'test' => $testName,
|
|
|
+ 'error' => $e->getMessage(),
|
|
|
+ 'trace' => $e->getTraceAsString()
|
|
|
+ ];
|
|
|
+
|
|
|
+ Log::error("测试失败: {$testName}", [
|
|
|
+ 'error' => $e->getMessage(),
|
|
|
+ 'trace' => $e->getTraceAsString()
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 输出测试套件开始信息
|
|
|
+ */
|
|
|
+ private function dumpSuiteStart(): void
|
|
|
+ {
|
|
|
+ dump("========================================");
|
|
|
+ dump(" 灾害去除系统 E2E 测试套件");
|
|
|
+ dump("========================================");
|
|
|
+ dump("测试环境: " . env('UNITTEST_URL', 'http://localhost:8000'));
|
|
|
+ dump("测试用户: " . TestConfig::getTestUserId());
|
|
|
+ dump("开始时间: " . date('Y-m-d H:i:s'));
|
|
|
+ dump("========================================");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 输出测试结果
|
|
|
+ */
|
|
|
+ private function dumpSuiteResults(): void
|
|
|
+ {
|
|
|
+ dump("========================================");
|
|
|
+ dump(" 测试结果统计");
|
|
|
+ dump("========================================");
|
|
|
+ dump("总测试数: " . $this->testResults['total']);
|
|
|
+ dump("通过数量: " . $this->testResults['passed']);
|
|
|
+ dump("失败数量: " . $this->testResults['failed']);
|
|
|
+
|
|
|
+ if (!empty($this->testResults['errors'])) {
|
|
|
+ dump("失败详情:");
|
|
|
+ foreach ($this->testResults['errors'] as $error) {
|
|
|
+ dump("- {$error['test']}: {$error['error']}");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $successRate = $this->testResults['total'] > 0
|
|
|
+ ? round(($this->testResults['passed'] / $this->testResults['total']) * 100, 2)
|
|
|
+ : 0;
|
|
|
+ dump("成功率: {$successRate}%");
|
|
|
+ dump("========================================");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 输出测试套件结束信息
|
|
|
+ */
|
|
|
+ private function dumpSuiteEnd(): void
|
|
|
+ {
|
|
|
+ dump("结束时间: " . date('Y-m-d H:i:s'));
|
|
|
+ dump("========================================");
|
|
|
+ dump(" 灾害去除系统 E2E 测试套件完成");
|
|
|
+ dump("========================================");
|
|
|
+ }
|
|
|
+}
|