Skip to content

Commit

Permalink
Merge pull request #4 from mleczakm/master
Browse files Browse the repository at this point in the history
Tests for pwz validator
  • Loading branch information
mleczakm authored May 3, 2017
2 parents c49bfd6 + 00ca34c commit bf30e7a
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Symfony2 bundle with Polish validators
[![Build status](https://travis-ci.org/kiczort/polish-validator-bundle.svg)](http://travis-ci.org/kiczort/polish-validator-bundle)
[![Scrutinizer Quality Score](https://img.shields.io/scrutinizer/g/kiczort/polish-validator-bundle.svg)](https://scrutinizer-ci.com/g/kiczort/polish-validator-bundle/)

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


# Installation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

/*
* This file is part of the Polish Validator Bundle package.
*
* (c) Grzegorz Koziński
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Kiczort\PolishValidatorBundle\Tests\Constraints;

use Kiczort\PolishValidatorBundle\Validator\Constraints\Pwz;
use Kiczort\PolishValidatorBundle\Validator\Constraints\PwzValidator;
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
use Symfony\Component\Validator\Validation;

/**
* @author Michał Mleczko
*/
class PwzValidatorTest extends AbstractConstraintValidatorTest
{
public function testNullIsValid()
{
$this->validator->validate(null, new Pwz());

$this->assertNoViolation();
}

public function testEmptyStringIsValid()
{
$this->validator->validate('', new Pwz());

$this->assertNoViolation();
}

/**
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
*/
public function testExpectsStringCompatibleType()
{
$this->validator->validate(new \stdClass(), new Pwz());
}

/**
* @dataProvider getValidPwzNumbers
*/
public function testValidPwz($pwz)
{
$this->validator->validate($pwz, new Pwz());

$this->assertNoViolation();
}

/**
* @dataProvider getInvalidPwzNumbers
*/
public function testInvalidPwz($pwz)
{
$constraint = new Pwz(array(
'message' => 'myMessage',
));

$this->validator->validate($pwz, $constraint);

$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"' . $pwz . '"')
->assertRaised();
}

/**
* @return array
*/
public function getValidPwzNumbers()
{
return array(
array('7305386'),
array('7520143'),
array('5773472'),
array('1241156'),
array('8839283'),
array('4470910'),
array('4850185'),
);
}

/**
* @return array
*/
public function getInvalidPwzNumbers()
{
return array(
array('0'),
array('0000000000000'),
array('0000000'),
array('1111111'),
array('2222222'),
);
}

/**
* @return PwzValidator
*/
protected function createValidator()
{
return new PwzValidator();
}

protected function getApiVersion()
{
return Validation::API_VERSION_2_5_BC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class Pwz extends Constraint
{
public $nonValidMessage = 'PWZ number is invalid';
public $message = 'This is not a valid PWZ number.';

/**
* {@inheritdoc}
Expand Down

0 comments on commit bf30e7a

Please sign in to comment.