| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace Tests\Unit\Pet;
- use PHPUnit\Framework\TestCase;
- use App\Module\Pet\Services\PetActiveSkillService;
- /**
- * 宠物激活技能服务测试
- */
- class PetActiveSkillServiceTest extends TestCase
- {
- /**
- * 测试服务层方法存在性
- */
- public function test_service_methods_exist()
- {
- // 测试主要方法是否存在
- $this->assertTrue(method_exists(PetActiveSkillService::class, 'processActiveSkills'));
- $this->assertTrue(method_exists(PetActiveSkillService::class, 'processSkill'));
- }
- /**
- * 测试Job类重构后的简洁性
- */
- public function test_job_class_is_simplified()
- {
- $jobClass = new \ReflectionClass(\App\Module\Pet\Jobs\ProcessActiveSkillsJob::class);
- // 检查Job类的方法数量是否减少(应该只有run和payload方法)
- $methods = $jobClass->getMethods(\ReflectionMethod::IS_PUBLIC);
- $publicMethods = array_filter($methods, function($method) {
- return $method->getDeclaringClass()->getName() === \App\Module\Pet\Jobs\ProcessActiveSkillsJob::class;
- });
- // 应该只有run和payload两个公共方法
- $this->assertLessThanOrEqual(2, count($publicMethods), 'Job类应该保持简洁,只有必要的方法');
- }
- /**
- * 测试Job类是否正确使用服务层
- */
- public function test_job_uses_service_layer()
- {
- $jobClass = new \ReflectionClass(\App\Module\Pet\Jobs\ProcessActiveSkillsJob::class);
- $runMethod = $jobClass->getMethod('run');
- // 获取run方法的源代码
- $filename = $jobClass->getFileName();
- $startLine = $runMethod->getStartLine();
- $endLine = $runMethod->getEndLine();
- $lines = file($filename);
- $methodCode = implode('', array_slice($lines, $startLine - 1, $endLine - $startLine + 1));
- // 检查是否调用了服务层
- $this->assertStringContainsString('PetActiveSkillService::processActiveSkills', $methodCode, 'Job应该调用服务层方法');
- }
- }
|