| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace Tests\Unit\ThirdParty;
- use PHPUnit\Framework\TestCase;
- /**
- * URS Request机制测试
- *
- * 测试重构后的URS Request类是否正确实现单一职责原则
- * 验证每个Request类只处理一种特定的请求类型
- */
- class UrsRequestTest extends TestCase
- {
- /**
- * 测试URS Request类是否存在
- */
- public function testUrsRequestClassesExist()
- {
- // 测试获取用户信息Request类
- $this->assertTrue(
- class_exists('ThirdParty\\Urs\\Request\\UrsGetUserInfoRequest'),
- 'UrsGetUserInfoRequest类应该存在'
- );
- // 测试获取用户团队关系Request类
- $this->assertTrue(
- class_exists('ThirdParty\\Urs\\Request\\UrsGetUserTeamRequest'),
- 'UrsGetUserTeamRequest类应该存在'
- );
- // 测试获取用户下级统计Request类
- $this->assertTrue(
- class_exists('ThirdParty\\Urs\\Request\\UrsGetUserLevelCountRequest'),
- 'UrsGetUserLevelCountRequest类应该存在'
- );
- }
- /**
- * 测试URS服务类是否存在
- */
- public function testUrsServiceClassExists()
- {
- $this->assertTrue(
- class_exists('ThirdParty\\Urs\\Services\\UrsService'),
- 'UrsService类应该存在'
- );
- }
- /**
- * 测试只存在3个URS Request类,没有多余的类
- */
- public function testOnlyThreeUrsRequestClassesExist()
- {
- // 确保不存在之前错误创建的Request类
- $nonExistentClasses = [
- 'ThirdParty\\Urs\\Request\\UrsRegisterRequest',
- 'ThirdParty\\Urs\\Request\\UrsDepositRequest',
- 'ThirdParty\\Urs\\Request\\UrsWithdrawRequest',
- 'ThirdParty\\Urs\\Request\\UrsCheckBalanceRequest',
- ];
- foreach ($nonExistentClasses as $className) {
- $this->assertFalse(
- class_exists($className),
- "{$className}不应该存在,因为URS没有提供对应的接口"
- );
- }
- }
- /**
- * 测试URS文件是否存在
- */
- public function testUrsFilesExist()
- {
- $expectedFiles = [
- 'ThirdParty/Urs/Request/UrsGetUserInfoRequest.php',
- 'ThirdParty/Urs/Request/UrsGetUserTeamRequest.php',
- 'ThirdParty/Urs/Request/UrsGetUserLevelCountRequest.php',
- 'ThirdParty/Urs/Services/UrsService.php',
- ];
- foreach ($expectedFiles as $file) {
- $this->assertFileExists(
- $file,
- "文件 {$file} 应该存在"
- );
- }
- }
- /**
- * 测试删除的文件不存在
- */
- public function testDeletedFilesDoNotExist()
- {
- $deletedFiles = [
- 'ThirdParty/Urs/Request/UrsRegisterRequest.php',
- 'ThirdParty/Urs/Request/UrsDepositRequest.php',
- 'ThirdParty/Urs/Request/UrsWithdrawRequest.php',
- 'ThirdParty/Urs/Request/UrsCheckBalanceRequest.php',
- ];
- foreach ($deletedFiles as $file) {
- $this->assertFileDoesNotExist(
- $file,
- "文件 {$file} 不应该存在,因为对应的接口不存在"
- );
- }
- }
- }
|