1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Validator |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2017 pudelek.org.pl |
6
|
|
|
* |
7
|
|
|
* @license MIT License (MIT) |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view source file |
10
|
|
|
* that is bundled with this package in the file LICENSE |
11
|
|
|
* |
12
|
|
|
* @author Marcin Pudełek <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace mrcnpdlk\Validator; |
16
|
|
|
|
17
|
|
|
use mrcnpdlk\Validator\Types\Pesel; |
18
|
|
|
|
19
|
|
|
class PeselTest extends TestCase |
20
|
|
|
{ |
21
|
|
View Code Duplication |
public function testPeselMaleValid() |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$defNr = '12271402999'; |
24
|
|
|
$res = new Pesel($defNr); |
25
|
|
|
$this->assertEquals('12271402999', $res->get()); |
26
|
|
|
$this->assertEquals('2012-07-14', $res->getBirthDate()); |
27
|
|
|
$this->assertEquals(Pesel::SEX_M, $res->getSex()); |
28
|
|
|
$this->assertEquals(true, $res->getAge() > 3); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public function testPeselFemaleValid() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$defNr = '30082916746'; |
34
|
|
|
$res = new Pesel($defNr); |
35
|
|
|
$this->assertEquals('30082916746', $res->get()); |
36
|
|
|
$this->assertEquals('1930-08-29', $res->getBirthDate()); |
37
|
|
|
$this->assertEquals(Pesel::SEX_F, $res->getSex()); |
38
|
|
|
$this->assertEquals(true, $res->getAge() > 86); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
View Code Duplication |
public function testPeselOldValid() |
|
|
|
|
42
|
|
|
{ |
43
|
|
|
$defNr = '11880804152'; |
44
|
|
|
$res = new Pesel($defNr); |
45
|
|
|
$this->assertEquals('11880804152', $res->get()); |
46
|
|
|
$this->assertEquals('1811-08-08', $res->getBirthDate()); |
47
|
|
|
$this->assertEquals(Pesel::SEX_M, $res->getSex()); |
48
|
|
|
$this->assertEquals(true, $res->getAge() > 205); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @expectedException \mrcnpdlk\Validator\Exception |
53
|
|
|
*/ |
54
|
|
|
public function testPeselInvalidChecksum() |
55
|
|
|
{ |
56
|
|
|
new Pesel('12271402990'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @expectedException \mrcnpdlk\Validator\Exception |
61
|
|
|
*/ |
62
|
|
|
public function testPeselInvalidRegex() |
63
|
|
|
{ |
64
|
|
|
new Pesel('3008291674'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.