|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sprain\SwissQrBill\Tests\Constraints; |
|
4
|
|
|
|
|
5
|
|
|
use Sprain\SwissQrBill\Constraints\ValidCreditorReference; |
|
6
|
|
|
use Sprain\SwissQrBill\Constraints\ValidCreditorReferenceValidator; |
|
7
|
|
|
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; |
|
8
|
|
|
|
|
9
|
|
|
class ValidCreditorReferenceTest extends ConstraintValidatorTestCase |
|
10
|
|
|
{ |
|
11
|
|
|
protected function createValidator() |
|
12
|
|
|
{ |
|
13
|
|
|
return new ValidCreditorReferenceValidator(); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
public function testNullIsValid() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->validator->validate(null, new ValidCreditorReference()); |
|
19
|
|
|
|
|
20
|
|
|
$this->assertNoViolation(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function testEmptyStringIsValid() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->validator->validate('', new ValidCreditorReference()); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertNoViolation(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @dataProvider getValidCreditorReferences |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testValidCreditorReferences($value) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->validator->validate($value, new ValidCreditorReference()); |
|
36
|
|
|
|
|
37
|
|
|
$this->assertNoViolation(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getValidCreditorReferences() |
|
41
|
|
|
{ |
|
42
|
|
|
return [ |
|
43
|
|
|
['RF45 1234 5123 45'], |
|
44
|
|
|
['RF451234512345'] |
|
45
|
|
|
]; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @dataProvider getInvalidCreditorReferences |
|
50
|
|
|
*/ |
|
51
|
|
|
public function testInvalidCreditorReferences($creditorReference) |
|
52
|
|
|
{ |
|
53
|
|
|
$constraint = new ValidCreditorReference(array( |
|
54
|
|
|
'message' => 'myMessage', |
|
55
|
|
|
)); |
|
56
|
|
|
|
|
57
|
|
|
$this->validator->validate($creditorReference, $constraint); |
|
58
|
|
|
|
|
59
|
|
|
$this->buildViolation('myMessage') |
|
60
|
|
|
->setParameter('{{ string }}', $creditorReference) |
|
61
|
|
|
->assertRaised(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getInvalidCreditorReferences() |
|
65
|
|
|
{ |
|
66
|
|
|
return [ |
|
67
|
|
|
['RF43 1234 5123 45'], |
|
68
|
|
|
['RF431234512345'], |
|
69
|
|
|
['foo'] |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|