Skip to content

Commit 6d2641d

Browse files
committed
Test rule Name
1 parent 9e89dfe commit 6d2641d

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tests/Rules/NameTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
namespace Arifszn\AdvancedValidation\Tests\Rules;
4+
5+
use Arifszn\AdvancedValidation\Rules\Name;
6+
use Arifszn\AdvancedValidation\Tests\TestCase;
7+
8+
class NameTest extends TestCase
9+
{
10+
/**
11+
* @dataProvider providerWithoutAllowNumber
12+
*/
13+
public function testValidationWithoutAllowNumber($result, $value)
14+
{
15+
$this->assertEquals($result, (new Name(false))->passes('foo', $value));
16+
}
17+
18+
/**
19+
* @dataProvider providerWithAllowNumber
20+
*/
21+
public function testValidationWithAllowNumber($result, $value)
22+
{
23+
$this->assertEquals($result, (new Name(true))->passes('foo', $value));
24+
}
25+
26+
public function providerWithoutAllowNumber()
27+
{
28+
return array_merge($this->shared(), [
29+
[false, '1234 abc DEF'],
30+
[false, '1234abcDEF'],
31+
[false, '消极的123'],
32+
]);
33+
}
34+
35+
public function providerWithAllowNumber()
36+
{
37+
return array_merge($this->shared(), [
38+
[true, '1234 abc DEF'],
39+
[true, '1234abcDEF'],
40+
[true, '消极的123'],
41+
]);
42+
}
43+
44+
private function shared()
45+
{
46+
return [
47+
[true, 'foobar'],
48+
[true, 'foobar'],
49+
[true, 'a'],
50+
[true, '消极的'],
51+
[true, '###'],
52+
[true, '**'],
53+
[false, '😀'],
54+
[false, 'john 😀'],
55+
[false, ''],
56+
[false, ' '],
57+
];
58+
}
59+
}

0 commit comments

Comments
 (0)