Skip to content

Commit bf30e7a

Browse files
authored
Merge pull request #4 from mleczakm/master
Tests for pwz validator
2 parents c49bfd6 + 00ca34c commit bf30e7a

File tree

3 files changed

+116
-2
lines changed

3 files changed

+116
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Symfony2 bundle with Polish validators
66
[![Build status](https://travis-ci.org/kiczort/polish-validator-bundle.svg)](http://travis-ci.org/kiczort/polish-validator-bundle)
77
[![Scrutinizer Quality Score](https://img.shields.io/scrutinizer/g/kiczort/polish-validator-bundle.svg)](https://scrutinizer-ci.com/g/kiczort/polish-validator-bundle/)
88

9-
This is Symfony2 bundle with validators for Polish identification numbers like: PESEL, NIP, REGON.
9+
This is Symfony2 bundle with validators for Polish identification numbers like: PESEL, NIP, REGON and PWZ.
1010

1111

1212
# Installation
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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\Pwz;
15+
use Kiczort\PolishValidatorBundle\Validator\Constraints\PwzValidator;
16+
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
17+
use Symfony\Component\Validator\Validation;
18+
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+
}

src/Kiczort/PolishValidatorBundle/Validator/Constraints/Pwz.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121
class Pwz extends Constraint
2222
{
23-
public $nonValidMessage = 'PWZ number is invalid';
23+
public $message = 'This is not a valid PWZ number.';
2424

2525
/**
2626
* {@inheritdoc}

0 commit comments

Comments
 (0)