/
IsNullTest.php
100 lines (86 loc) · 2.13 KB
/
IsNullTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
declare(strict_types=1);
namespace Tests\Validate\Validator;
use Leevel\Kernel\Utils\Api;
use Leevel\Validate\Validator;
use PHPUnit\Framework\Attributes\DataProvider;
use Tests\TestCase;
#[Api([
'zh-CN:title' => '验证器.是否为 null',
'path' => 'validate/validator/isnull',
])]
final class IsNullTest extends TestCase
{
#[DataProvider('baseUseProvider')]
#[Api([
'zh-CN:title' => '验证通过的数据',
'zh-CN:description' => <<<'EOT'
以下是通过的校验数据示例。
``` php
{[\Leevel\Kernel\Utils\Doc::getMethodBody(\Tests\Validate\Validator\IsNullTest::class, 'baseUseProvider')]}
```
上面的数据是测试的数据提供者。
EOT,
])]
public function testBaseUse($value): void
{
$validate = new Validator(
[
'name' => $value,
],
[
'name' => 'is_null',
]
);
self::assertTrue($validate->success());
}
public static function baseUseProvider(): array
{
$val = null;
return [
[null],
[$val],
];
}
#[DataProvider('badProvider')]
#[Api([
'zh-CN:title' => '未验证通过的数据',
'zh-CN:description' => <<<'EOT'
以下是未通过的校验数据示例。
``` php
{[\Leevel\Kernel\Utils\Doc::getMethodBody(\Tests\Validate\Validator\IsNullTest::class, 'badProvider')]}
```
上面的数据是测试的数据提供者。
EOT,
])]
public function testBad($value): void
{
$validate = new Validator(
[
'name' => $value,
],
[
'name' => 'is_null',
]
);
self::assertFalse($validate->success());
}
public static function badProvider(): array
{
return [
[' '],
['not numeric'],
[new \stdClass()],
[['foo', 'bar']],
[[1, 2]],
['this is a string'],
['foo'],
['bar'],
['hello'],
['world'],
[true],
[1],
[[[], []]],
];
}
}