| 123456789101112131415161718192021222324252627282930313233343536 |
- <?php
- namespace Tests\Unit;
- use App\Services\Agent\AgentDomainService;
- use PHPUnit\Framework\TestCase;
- use ReflectionMethod;
- /** 推广域名绑定什么就保存、返回什么;主机名用于唯一性和注册识别。 */
- class AgentDomainServiceTest extends TestCase
- {
- private function call(string $method, string $value)
- {
- $reflection = new ReflectionMethod(AgentDomainService::class, $method);
- $reflection->setAccessible(true);
- return $reflection->invoke(new AgentDomainService(), $value);
- }
- public function test_bound_value_is_kept_exactly_and_host_is_extracted(): void
- {
- foreach ([
- 'https://pc.example.com' => 'pc.example.com',
- ' https://pc.example.com/#/user/register?ref=A1 ' => 'pc.example.com',
- 'h5.Example.com/reg' => 'h5.example.com',
- 'http://pc.example.com:8080/x' => 'pc.example.com',
- ] as $input => $host) {
- $this->assertSame(trim($input), $this->call('normalize', $input), 'saved exactly as entered (only trimmed)');
- $this->assertSame($host, $this->call('host', trim($input)));
- }
- $this->assertSame('', $this->call('normalize', ' '));
- foreach (['ftp://pc.example.com', 'https://', 'pc example.com'] as $bad) {
- try { $this->call('normalize', $bad); $this->fail($bad); }
- catch (\InvalidArgumentException $e) { $this->assertSame('域名格式错误', $e->getMessage()); }
- }
- }
- }
|