Skip to content

Commit 67a6a7c

Browse files
Prepare test cases
1 parent 3251249 commit 67a6a7c

File tree

9 files changed

+238
-40
lines changed

9 files changed

+238
-40
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ language: php
22

33
php:
44
- 7.1
5-
- 7.2
6-
- 7.3
75

86
env:
97
matrix:

phpunit.xml.dist

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,4 @@
1919
<directory suffix=".php">src/</directory>
2020
</whitelist>
2121
</filter>
22-
<logging>
23-
<log type="tap" target="build/report.tap"/>
24-
<log type="junit" target="build/report.junit.xml"/>
25-
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
26-
<log type="coverage-text" target="build/coverage.txt"/>
27-
<log type="coverage-clover" target="build/logs/clover.xml"/>
28-
</logging>
2922
</phpunit>

src/Rules/IdVN.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,19 @@ private static function idPregFormatPart(bool $old): string
5151

5252
private static function cIdPregFormatPart(): string
5353
{
54-
return strtr('(::head::)\d{10}', '::head::', implode('|', [
55-
'0[012468]',
56-
'1[0124579]',
57-
'2[024-7]',
58-
'3[013-8]',
59-
'4[0245689]',
60-
'5[12468]',
61-
'6[024678]',
62-
'7[024579]',
63-
'8[0234679]',
64-
'9[1-6]'
65-
]));
54+
return strtr('(::head::)\d{10}', [
55+
'::head::' => implode('|', [
56+
'0[012468]',
57+
'1[0124579]',
58+
'2[024-7]',
59+
'3[013-8]',
60+
'4[0245689]',
61+
'5[12468]',
62+
'6[024678]',
63+
'7[024579]',
64+
'8[0234679]',
65+
'9[1-6]'
66+
])
67+
]);
6668
}
6769
}

src/Rules/LandLineVN.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ class LandLineVN extends AbstractStaticRegexRule
1616

1717
public static function pregFormat(): string
1818
{
19-
return strtr('~^(\+?84|0)(::head::)\d{7}$~', '::head::', implode('|', [
20-
'20[3-9]',
21-
'21[0-689]',
22-
'22[0-25-9]',
23-
'23[2-9]',
24-
'24[0-9]',
25-
'25[124-9]',
26-
'26[0-39]',
27-
'27[0-7]',
28-
'28[0-9]',
29-
'29[0-4679]'
30-
]));
19+
return strtr('~^(\+?84|0)(::head::)\d{7}$~', [
20+
'::head::' => implode('|', [
21+
'20[3-9]',
22+
'21[0-689]',
23+
'22[0-25-9]',
24+
'23[2-9]',
25+
'24[0-9]',
26+
'25[124-9]',
27+
'26[0-39]',
28+
'27[0-7]',
29+
'28[0-9]',
30+
'29[0-4679]'
31+
])
32+
]);
3133
}
3234
}

src/Rules/MobileVN.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ class MobileVN extends AbstractStaticRegexRule
1616

1717
public static function pregFormat(): string
1818
{
19-
return strtr('~^(\+?84|0)(::head::)\d{7}$~', '::head::', implode('|', [
20-
'3[2-9]',
21-
'5[2689]',
22-
'7(0|[6-9])',
23-
'8[1-9]',
24-
'9[0-9]',
25-
]));
19+
return strtr('~^(\+?84|0)(::head::)\d{7}$~', [
20+
'::head::' => implode('|', [
21+
'3[2-9]',
22+
'5[2689]',
23+
'7(0|[6-9])',
24+
'8[1-9]',
25+
'9[0-9]',
26+
])
27+
]);
2628
}
2729

2830
}

src/Validator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
use Respect\Validation\Factory;
1212

1313
/**
14+
* @method static Validator landLineVN()
15+
* @method static Validator mobileVN()
16+
* @method static Validator ipVN()
17+
* @method static Validator idVN()
18+
*
1419
* @author Vuong Minh <vuongxuongminh@gmail.com>
1520
* @since 1.0.0
1621
*/

tests/Rules/LandLineVNTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/validation
4+
* @copyright (c) PHP Viet
5+
* @license [MIT](https://opensource.org/licenses/MIT)
6+
*/
7+
8+
namespace PHPViet\Validation\Tests\Rules;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use PHPViet\Validation\Rules\LandLineVN;
12+
13+
/**
14+
* @author Vuong Minh <vuongxuongminh@gmail.com>
15+
* @since 1.0.0
16+
*/
17+
class LandLineVNTest extends TestCase
18+
{
19+
/**
20+
* @var LandLineVN
21+
*/
22+
protected $validator;
23+
24+
protected function setUp()
25+
{
26+
$this->validator = new LandLineVN;
27+
}
28+
29+
/**
30+
* @dataProvider providerValid
31+
*/
32+
public function testValidShouldReturnTrue($input)
33+
{
34+
$this->assertTrue($this->validator->__invoke($input));
35+
$this->assertTrue($this->validator->assert($input));
36+
$this->assertTrue($this->validator->check($input));
37+
}
38+
39+
/**
40+
* @dataProvider providerInvalid
41+
*/
42+
public function testInvalidShouldThrowPhoneException($input)
43+
{
44+
$this->expectException('\PHPViet\Validation\Exceptions\LandLineVNException');
45+
$this->assertFalse($this->validator->__invoke($input));
46+
$this->assertFalse($this->validator->assert($input));
47+
}
48+
49+
public function providerValid()
50+
{
51+
return [
52+
['+842838564399'],
53+
['02838564399'],
54+
['842838564399'],
55+
['02038364399'],
56+
['02168964399'],
57+
['02258864399'],
58+
['02398764399'],
59+
['02428569399'],
60+
['02598566399'],
61+
['02608565499'],
62+
['02778564599'],
63+
['02898564299'],
64+
['02942564799'],
65+
];
66+
}
67+
68+
public function providerInvalid()
69+
{
70+
return [
71+
['+8428385643099'],
72+
['028385643199'],
73+
['8428385644399'],
74+
['02038364399a'],
75+
['02168964399!'],
76+
['02258 864399'],
77+
['02318764399'],
78+
['02538566399'],
79+
['02678565499'],
80+
['02798564599'],
81+
['02952564799'],
82+
];
83+
}
84+
}

tests/Rules/MobileVNTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/validation
4+
* @copyright (c) PHP Viet
5+
* @license [MIT](https://opensource.org/licenses/MIT)
6+
*/
7+
8+
namespace PHPViet\Validation\Tests\Rules;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use PHPViet\Validation\Rules\MobileVN;
12+
13+
/**
14+
* @author Vuong Minh <vuongxuongminh@gmail.com>
15+
* @since 1.0.0
16+
*/
17+
class MobileVNTest extends TestCase
18+
{
19+
/**
20+
* @var MobileVN
21+
*/
22+
protected $validator;
23+
24+
protected function setUp()
25+
{
26+
$this->validator = new MobileVN;
27+
}
28+
29+
/**
30+
* @dataProvider providerValid
31+
*/
32+
public function testValidShouldReturnTrue($input)
33+
{
34+
$this->assertTrue($this->validator->__invoke($input));
35+
$this->assertTrue($this->validator->assert($input));
36+
$this->assertTrue($this->validator->check($input));
37+
}
38+
39+
/**
40+
* @dataProvider providerInvalid
41+
*/
42+
public function testInvalidShouldThrowPhoneException($input)
43+
{
44+
$this->expectException('\PHPViet\Validation\Exceptions\MobileVNException');
45+
$this->assertFalse($this->validator->__invoke($input));
46+
$this->assertFalse($this->validator->assert($input));
47+
}
48+
49+
public function providerValid()
50+
{
51+
return [
52+
['84982527982'],
53+
['84973776072'],
54+
['+84917749254'],
55+
['84904770053']
56+
];
57+
}
58+
59+
public function providerInvalid()
60+
{
61+
return [
62+
['asdasdasdasd1231a'],
63+
['!@#!@#1123123..123'],
64+
['09091139111'],
65+
['016485754635'],
66+
['0603366854'],
67+
['070336685a'],
68+
['+842838564399'],
69+
['02838564399'],
70+
['842838564399'],
71+
['02038364399'],
72+
['02168964399'],
73+
['02258864399'],
74+
['02398764399'],
75+
['02428569399'],
76+
['02598566399'],
77+
['02608565499'],
78+
['02778564599'],
79+
['02898564299'],
80+
['02942564799']
81+
];
82+
}
83+
}

tests/ValidatorTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/validation
4+
* @copyright (c) PHP Viet
5+
* @license [MIT](https://opensource.org/licenses/MIT)
6+
*/
7+
8+
namespace PHPViet\Validation\Tests;
9+
10+
use PHPUnit\Framework\TestCase;
11+
use PHPViet\Validation\Validator;
12+
use Respect\Validation\Factory;
13+
14+
/**
15+
* @author Vuong Minh <vuongxuongminh@gmail.com>
16+
* @since 1.0.0
17+
*/
18+
class ValidatorTest extends TestCase
19+
{
20+
21+
public function testSetFactoryHavePrefixRules()
22+
{
23+
$factory = new Factory;
24+
$this->assertNotContains('\\PHPViet\\Validation\\Rules\\', $factory->getRulePrefixes());
25+
Validator::setFactory($factory);
26+
$this->assertContains('\\PHPViet\\Validation\\Rules\\', $factory->getRulePrefixes());
27+
}
28+
29+
}

0 commit comments

Comments
 (0)