验证器.是否为 ipv4
Testing Is Documentation
Uses
php
<?php
use Leevel\Kernel\Utils\Api;
use Leevel\Validate\Validator;
use PHPUnit\Framework\Attributes\DataProvider;
验证通过的数据
以下是通过的校验数据示例。
php
# Tests\Validate\Validator\Ipv4Test::baseUseProvider
public static function baseUseProvider(): array
{
return [
['8.8.8.8'],
['8.8.4.4'],
['127.0.0.1'],
];
}
上面的数据是测试的数据提供者。
php
public function testBaseUse($value): void
{
$validate = new Validator(
[
'name' => $value,
],
[
'name' => 'ipv4',
]
);
self::assertTrue($validate->success());
}
未验证通过的数据
以下是未通过的校验数据示例。
php
# Tests\Validate\Validator\Ipv4Test::badProvider
public static function badProvider(): array
{
return [
['2022222201:3CA1:010F:001A:121B:0000:0000:0010'],
['2001:000000:0000:001A:0000:0000:0000:0010'],
['8.8999.8.8'],
['8.2228.4.4'],
[' 127.0.0.1 '],
['20222222201:4860:4860::8888'],
['9999999:4860:4860::8844'],
[false],
[1.1],
['0.0'],
['-0.0'],
];
}
上面的数据是测试的数据提供者。
php
public function testBad($value): void
{
$validate = new Validator(
[
'name' => $value,
],
[
'name' => 'ipv4',
]
);
self::assertFalse($validate->success());
}