验证器.是否为 ipv6

Testing Is Documentation

tests/Validate/Validator/Ipv6Test.php验证器.是否为 ipv6 - 图1

Uses

  1. <?php
  2. use Leevel\Validate\Validator;

验证通过的数据

以下是通过的校验数据示例。

  1. # Tests\Validate\Validator\Ipv6Test::baseUseProvider
  2. public function baseUseProvider(): array
  3. {
  4. return [
  5. ['2001:3CA1:010F:001A:121B:0000:0000:0010'],
  6. ['2001:0000:0000:001A:0000:0000:0000:0010'],
  7. ['2001:4860:4860::8888'],
  8. ['2001:4860:4860::8844'],
  9. ];
  10. }

上面的数据是测试的数据提供者。

  1. public function testBaseUse($value): void
  2. {
  3. $validate = new Validator(
  4. [
  5. 'name' => $value,
  6. ],
  7. [
  8. 'name' => 'ipv6',
  9. ]
  10. );
  11. $this->assertTrue($validate->success());
  12. }

未验证通过的数据

以下是未通过的校验数据示例。

  1. # Tests\Validate\Validator\Ipv6Test::badProvider
  2. public function badProvider(): array
  3. {
  4. return [
  5. ['2022222201:3CA1:010F:001A:121B:0000:0000:0010'],
  6. ['2001:000000:0000:001A:0000:0000:0000:0010'],
  7. ['8.8999.8.8'],
  8. ['8.2228.4.4'],
  9. [' 127.0.0.1 '],
  10. ['20222222201:4860:4860::8888'],
  11. ['9999999:4860:4860::8844'],
  12. [false],
  13. [1.1],
  14. ['0.0'],
  15. ['-0.0'],
  16. ];
  17. }

上面的数据是测试的数据提供者。

  1. public function testBad($value): void
  2. {
  3. $validate = new Validator(
  4. [
  5. 'name' => $value,
  6. ],
  7. [
  8. 'name' => 'ipv6',
  9. ]
  10. );
  11. $this->assertFalse($validate->success());
  12. }