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\Nip; |
15
|
|
|
use Kiczort\PolishValidatorBundle\Validator\Constraints\NipValidator; |
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 NipValidatorTest extends AbstractConstraintValidatorTest |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @return NipValidator |
26
|
|
|
*/ |
27
|
|
|
protected function createValidator() |
28
|
|
|
{ |
29
|
|
|
return new NipValidator(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testNullIsValid() |
33
|
|
|
{ |
34
|
|
|
$this->validator->validate(null, new Nip()); |
35
|
|
|
|
36
|
|
|
$this->assertNoViolation(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testEmptyStringIsValid() |
40
|
|
|
{ |
41
|
|
|
$this->validator->validate('', new Nip()); |
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 Nip()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @dataProvider getValidNipNumbers |
56
|
|
|
*/ |
57
|
|
|
public function testValidNip($nip) |
58
|
|
|
{ |
59
|
|
|
$this->validator->validate($nip, new Nip()); |
60
|
|
|
|
61
|
|
|
$this->assertNoViolation(); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @dataProvider getInvalidNipNumbers |
66
|
|
|
*/ |
67
|
|
|
public function testInvalidNip($nip) |
68
|
|
|
{ |
69
|
|
|
$constraint = new Nip(array( |
70
|
|
|
'message' => 'myMessage', |
71
|
|
|
)); |
72
|
|
|
|
73
|
|
|
$this->validator->validate($nip, $constraint); |
74
|
|
|
|
75
|
|
|
$this->buildViolation('myMessage') |
76
|
|
|
->setParameter('{{ value }}', '"' . $nip . '"') |
77
|
|
|
->assertRaised(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
|
|
public function getValidNipNumbers() |
84
|
|
|
{ |
85
|
|
|
return array( |
86
|
|
|
array('1234563218'), |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function getInvalidNipNumbers() |
94
|
|
|
{ |
95
|
|
|
return array( |
96
|
|
|
array('123456789'), |
97
|
|
|
array('12345678901'), |
98
|
|
|
array('0000000000'), |
99
|
|
|
array('123456789a'), |
100
|
|
|
array('1234563217'), |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
protected function getApiVersion() |
105
|
|
|
{ |
106
|
|
|
return Validation::API_VERSION_2_5_BC; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
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.