|
|
7 tháng trước cách đây | |
|---|---|---|
| .. | ||
| Urs | 7 tháng trước cách đây | |
| BaseRequestTest.php | 7 tháng trước cách đây | |
| README.md | 7 tháng trước cách đây | |
| ThirdPartyTestSuite.php | 7 tháng trước cách đây | |
| UrsCryptoServiceTest.php | 7 tháng trước cách đây | |
| UrsRequestTest.php | 7 tháng trước cách đây | |
本目录包含ThirdParty模块的PHPUnit测试用例,用于验证模块的功能正确性和代码质量。
tests/Unit/ThirdParty/
├── README.md # 本说明文件
├── ThirdPartyTestSuite.php # 测试套件组织器
├── BaseRequestTest.php # BaseRequest基类测试
├── UrsRequestTest.php # URS Request机制测试
└── UrsCryptoServiceTest.php # URS加密服务测试
测试ThirdParty模块的BaseRequest基类:
测试URS Request机制重构后的功能:
测试URS加密服务功能:
vendor/bin/phpunit tests/Unit/ThirdParty/
# 测试BaseRequest基类
vendor/bin/phpunit tests/Unit/ThirdParty/BaseRequestTest.php
# 测试URS Request机制
vendor/bin/phpunit tests/Unit/ThirdParty/UrsRequestTest.php
# 测试URS加密服务
vendor/bin/phpunit tests/Unit/ThirdParty/UrsCryptoServiceTest.php
# 测试URS Request类存在性
vendor/bin/phpunit tests/Unit/ThirdParty/UrsRequestTest.php --filter testUrsRequestClassesExist
# 测试加密解密功能
vendor/bin/phpunit tests/Unit/ThirdParty/UrsCryptoServiceTest.php --filter testEncryptDecryptRoundTrip
# 显示详细测试信息
vendor/bin/phpunit tests/Unit/ThirdParty/ --verbose
# 显示测试覆盖率(需要安装xdebug)
vendor/bin/phpunit tests/Unit/ThirdParty/ --coverage-text
当前测试统计信息:
各类测试分布:
// 好的测试方法名
public function testUrsRequestClassesExist()
public function testEncryptDecryptRoundTrip()
public function testSignatureVerification()
// 避免的命名
public function test1()
public function testSomething()
// 使用具体的断言方法
$this->assertTrue($condition, '描述性错误信息');
$this->assertEquals($expected, $actual, '描述性错误信息');
$this->assertInstanceOf(ClassName::class, $object);
// 避免通用断言
$this->assert($condition);
// 正确的异常测试
$this->expectException(ExceptionClass::class);
$this->expectExceptionMessage('预期的错误信息');
$object->methodThatShouldThrow();
/**
* @dataProvider validDataProvider
*/
public function testWithValidData($input, $expected)
{
$result = $this->service->process($input);
$this->assertEquals($expected, $result);
}
public function validDataProvider(): array
{
return [
'case1' => ['input1', 'expected1'],
'case2' => ['input2', 'expected2'],
];
}
这些测试应该集成到CI/CD流程中:
添加新测试时请遵循:
{功能名}Test.php{功能名}Testtest{具体功能描述}