BlankValidatorTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Tests\Constraints;
  11. use Symfony\Component\Validator\Constraints\Blank;
  12. use Symfony\Component\Validator\Constraints\BlankValidator;
  13. use Symfony\Component\Validator\Validation;
  14. class BlankValidatorTest extends AbstractConstraintValidatorTest
  15. {
  16. protected function getApiVersion()
  17. {
  18. return Validation::API_VERSION_2_5;
  19. }
  20. protected function createValidator()
  21. {
  22. return new BlankValidator();
  23. }
  24. public function testNullIsValid()
  25. {
  26. $this->validator->validate(null, new Blank());
  27. $this->assertNoViolation();
  28. }
  29. public function testBlankIsValid()
  30. {
  31. $this->validator->validate('', new Blank());
  32. $this->assertNoViolation();
  33. }
  34. /**
  35. * @dataProvider getInvalidValues
  36. */
  37. public function testInvalidValues($value, $valueAsString)
  38. {
  39. $constraint = new Blank(array(
  40. 'message' => 'myMessage',
  41. ));
  42. $this->validator->validate($value, $constraint);
  43. $this->buildViolation('myMessage')
  44. ->setParameter('{{ value }}', $valueAsString)
  45. ->setCode(Blank::NOT_BLANK_ERROR)
  46. ->assertRaised();
  47. }
  48. public function getInvalidValues()
  49. {
  50. return array(
  51. array('foobar', '"foobar"'),
  52. array(0, '0'),
  53. array(false, 'false'),
  54. array(1234, '1234'),
  55. );
  56. }
  57. }