| @@ 22-114 (lines=93) @@ | ||
| 19 | /** |
|
| 20 | * @author Michał Mleczko |
|
| 21 | */ |
|
| 22 | class PwzValidatorTest extends AbstractConstraintValidatorTest |
|
| 23 | { |
|
| 24 | public function testNullIsValid() |
|
| 25 | { |
|
| 26 | $this->validator->validate(null, new Pwz()); |
|
| 27 | ||
| 28 | $this->assertNoViolation(); |
|
| 29 | } |
|
| 30 | ||
| 31 | public function testEmptyStringIsValid() |
|
| 32 | { |
|
| 33 | $this->validator->validate('', new Pwz()); |
|
| 34 | ||
| 35 | $this->assertNoViolation(); |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException |
|
| 40 | */ |
|
| 41 | public function testExpectsStringCompatibleType() |
|
| 42 | { |
|
| 43 | $this->validator->validate(new \stdClass(), new Pwz()); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @dataProvider getValidPwzNumbers |
|
| 48 | */ |
|
| 49 | public function testValidPwz($pwz) |
|
| 50 | { |
|
| 51 | $this->validator->validate($pwz, new Pwz()); |
|
| 52 | ||
| 53 | $this->assertNoViolation(); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * @dataProvider getInvalidPwzNumbers |
|
| 58 | */ |
|
| 59 | public function testInvalidPwz($pwz) |
|
| 60 | { |
|
| 61 | $constraint = new Pwz(array( |
|
| 62 | 'message' => 'myMessage', |
|
| 63 | )); |
|
| 64 | ||
| 65 | $this->validator->validate($pwz, $constraint); |
|
| 66 | ||
| 67 | $this->buildViolation('myMessage') |
|
| 68 | ->setParameter('{{ value }}', '"' . $pwz . '"') |
|
| 69 | ->assertRaised(); |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * @return array |
|
| 74 | */ |
|
| 75 | public function getValidPwzNumbers() |
|
| 76 | { |
|
| 77 | return array( |
|
| 78 | array('7305386'), |
|
| 79 | array('7520143'), |
|
| 80 | array('5773472'), |
|
| 81 | array('1241156'), |
|
| 82 | array('8839283'), |
|
| 83 | array('4470910'), |
|
| 84 | array('4850185'), |
|
| 85 | ); |
|
| 86 | } |
|
| 87 | ||
| 88 | /** |
|
| 89 | * @return array |
|
| 90 | */ |
|
| 91 | public function getInvalidPwzNumbers() |
|
| 92 | { |
|
| 93 | return array( |
|
| 94 | array('0'), |
|
| 95 | array('0000000000000'), |
|
| 96 | array('0000000'), |
|
| 97 | array('1111111'), |
|
| 98 | array('2222222'), |
|
| 99 | ); |
|
| 100 | } |
|
| 101 | ||
| 102 | /** |
|
| 103 | * @return PwzValidator |
|
| 104 | */ |
|
| 105 | protected function createValidator() |
|
| 106 | { |
|
| 107 | return new PwzValidator(); |
|
| 108 | } |
|
| 109 | ||
| 110 | protected function getApiVersion() |
|
| 111 | { |
|
| 112 | return Validation::API_VERSION_2_5_BC; |
|
| 113 | } |
|
| 114 | } |
|
| 115 | ||
| @@ 22-113 (lines=92) @@ | ||
| 19 | /** |
|
| 20 | * @author Grzegorz Koziński <[email protected]> |
|
| 21 | */ |
|
| 22 | class RegonValidatorTest extends AbstractConstraintValidatorTest |
|
| 23 | { |
|
| 24 | public function testNullIsValid() |
|
| 25 | { |
|
| 26 | $this->validator->validate(null, new Regon()); |
|
| 27 | ||
| 28 | $this->assertNoViolation(); |
|
| 29 | } |
|
| 30 | ||
| 31 | public function testEmptyStringIsValid() |
|
| 32 | { |
|
| 33 | $this->validator->validate('', new Regon()); |
|
| 34 | ||
| 35 | $this->assertNoViolation(); |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException |
|
| 40 | */ |
|
| 41 | public function testExpectsStringCompatibleType() |
|
| 42 | { |
|
| 43 | $this->validator->validate(new \stdClass(), new Regon()); |
|
| 44 | } |
|
| 45 | ||
| 46 | /** |
|
| 47 | * @dataProvider getValidRegonNumbers |
|
| 48 | */ |
|
| 49 | public function testValidRegon($regon) |
|
| 50 | { |
|
| 51 | $this->validator->validate($regon, new Regon()); |
|
| 52 | ||
| 53 | $this->assertNoViolation(); |
|
| 54 | } |
|
| 55 | ||
| 56 | /** |
|
| 57 | * @dataProvider getInvalidRegonNumbers |
|
| 58 | */ |
|
| 59 | public function testInvalidRegon($regon) |
|
| 60 | { |
|
| 61 | $constraint = new Regon(array( |
|
| 62 | 'message' => 'myMessage', |
|
| 63 | )); |
|
| 64 | ||
| 65 | $this->validator->validate($regon, $constraint); |
|
| 66 | ||
| 67 | $this->buildViolation('myMessage') |
|
| 68 | ->setParameter('{{ value }}', '"' . $regon . '"') |
|
| 69 | ->assertRaised(); |
|
| 70 | } |
|
| 71 | ||
| 72 | /** |
|
| 73 | * @return array |
|
| 74 | */ |
|
| 75 | public function getValidRegonNumbers() |
|
| 76 | { |
|
| 77 | return array( |
|
| 78 | array('123456785'), |
|
| 79 | array('12345678512347'), |
|
| 80 | ); |
|
| 81 | } |
|
| 82 | ||
| 83 | /** |
|
| 84 | * @return array |
|
| 85 | */ |
|
| 86 | public function getInvalidRegonNumbers() |
|
| 87 | { |
|
| 88 | return array( |
|
| 89 | array('12345678512346'), |
|
| 90 | array('123456786'), |
|
| 91 | array('12345678a'), |
|
| 92 | array('1234567890123'), |
|
| 93 | array('123456789012'), |
|
| 94 | array('12345678901'), |
|
| 95 | array('1234567890'), |
|
| 96 | array('123456789012345'), |
|
| 97 | array('12345678'), |
|
| 98 | ); |
|
| 99 | } |
|
| 100 | ||
| 101 | /** |
|
| 102 | * @return RegonValidator |
|
| 103 | */ |
|
| 104 | protected function createValidator() |
|
| 105 | { |
|
| 106 | return new RegonValidator(); |
|
| 107 | } |
|
| 108 | ||
| 109 | protected function getApiVersion() |
|
| 110 | { |
|
| 111 | return Validation::API_VERSION_2_5_BC; |
|
| 112 | } |
|
| 113 | } |
|
| 114 | ||