1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Polish Validator Bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Grzegorz Koziński |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Kiczort\PolishValidatorBundle\Tests\Constraints; |
13
|
|
|
|
14
|
|
|
use Kiczort\PolishValidatorBundle\Validator\Constraints\Pesel; |
15
|
|
|
use Kiczort\PolishValidatorBundle\Validator\Constraints\PeselValidator; |
16
|
|
|
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest; |
17
|
|
|
use Symfony\Component\Validator\Validation; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Grzegorz Koziński <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class PeselValidatorTest extends AbstractConstraintValidatorTest |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @return PeselValidator |
26
|
|
|
*/ |
27
|
|
|
protected function createValidator() |
28
|
|
|
{ |
29
|
|
|
return new PeselValidator(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testNullIsValid() |
33
|
|
|
{ |
34
|
|
|
$this->validator->validate(null, new Pesel()); |
35
|
|
|
|
36
|
|
|
$this->assertNoViolation(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testEmptyStringIsValid() |
40
|
|
|
{ |
41
|
|
|
$this->validator->validate('', new Pesel()); |
42
|
|
|
|
43
|
|
|
$this->assertNoViolation(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException |
48
|
|
|
*/ |
49
|
|
|
public function testExpectsStringCompatibleType() |
50
|
|
|
{ |
51
|
|
|
$this->validator->validate(new \stdClass(), new Pesel()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @dataProvider getNoneStrictValidPeselNumbers |
56
|
|
|
*/ |
57
|
|
|
public function testValidPesel($pesel) |
58
|
|
|
{ |
59
|
|
|
$this->validator->validate($pesel, new Pesel()); |
60
|
|
|
|
61
|
|
|
$this->assertNoViolation(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @dataProvider getStrictValidPeselNumbers |
66
|
|
|
*/ |
67
|
|
|
public function testValidPeselStrict($pesel) |
68
|
|
|
{ |
69
|
|
|
$this->validator->validate($pesel, new Pesel(array( |
70
|
|
|
'strict' => true, |
71
|
|
|
))); |
72
|
|
|
|
73
|
|
|
$this->assertNoViolation(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @dataProvider getNoneStrictInvalidPeselNumbers |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function testInvalidPesel($pesel) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$constraint = new Pesel(array( |
82
|
|
|
'message' => 'myMessage', |
83
|
|
|
)); |
84
|
|
|
|
85
|
|
|
$this->validator->validate($pesel, $constraint); |
86
|
|
|
|
87
|
|
|
$this->buildViolation('myMessage') |
88
|
|
|
->setParameter('{{ value }}', '"' . $pesel . '"') |
89
|
|
|
->assertRaised(); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @dataProvider getStrictInvalidPeselNumbers |
94
|
|
|
*/ |
95
|
|
View Code Duplication |
public function testInvalidPeselStrict($pesel) |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$constraint = new Pesel(array( |
98
|
|
|
'strict' => true, |
99
|
|
|
'message' => 'myMessage', |
100
|
|
|
)); |
101
|
|
|
|
102
|
|
|
$this->validator->validate($pesel, $constraint); |
103
|
|
|
|
104
|
|
|
$this->buildViolation('myMessage') |
105
|
|
|
->setParameter('{{ value }}', '"' . $pesel . '"') |
106
|
|
|
->assertRaised(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @return array |
111
|
|
|
*/ |
112
|
|
|
public function getNoneStrictValidPeselNumbers() |
113
|
|
|
{ |
114
|
|
|
return array( |
115
|
|
|
array('55813111111'), |
116
|
|
|
array('44051401358'), |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return array |
122
|
|
|
*/ |
123
|
|
|
public function getStrictValidPeselNumbers() |
124
|
|
|
{ |
125
|
|
|
return array( |
126
|
|
|
array('44051401359'), |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return array |
132
|
|
|
*/ |
133
|
|
|
public function getNoneStrictInvalidPeselNumbers() |
134
|
|
|
{ |
135
|
|
|
return array( |
136
|
|
|
array('12314'), |
137
|
|
|
array('12314111111'), |
138
|
|
|
array('55813211111'), |
139
|
|
|
array('123a41f1111'), |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return array |
145
|
|
|
*/ |
146
|
|
|
public function getStrictInvalidPeselNumbers() |
147
|
|
|
{ |
148
|
|
|
return array( |
149
|
|
|
array('44051401358'), |
150
|
|
|
); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
protected function getApiVersion() |
154
|
|
|
{ |
155
|
|
|
return Validation::API_VERSION_2_5_BC; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.