-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from mleczakm/master
Tests for pwz validator
- Loading branch information
Showing
3 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
src/Kiczort/PolishValidatorBundle/Tests/Constraints/PwzValidatorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters