BlankValidatorTest.php 1.7 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\Tests\Component\Validator\Constraints;
  11. use Symfony\Component\Validator\Constraints\Blank;
  12. use Symfony\Component\Validator\Constraints\BlankValidator;
  13. class BlankValidatorTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected $validator;
  16. protected function setUp()
  17. {
  18. $this->validator = new BlankValidator();
  19. }
  20. protected function tearDown()
  21. {
  22. $this->validator = null;
  23. }
  24. public function testNullIsValid()
  25. {
  26. $this->assertTrue($this->validator->isValid(null, new Blank()));
  27. }
  28. public function testBlankIsValid()
  29. {
  30. $this->assertTrue($this->validator->isValid('', new Blank()));
  31. }
  32. /**
  33. * @dataProvider getInvalidValues
  34. */
  35. public function testInvalidValues($date)
  36. {
  37. $this->assertFalse($this->validator->isValid($date, new Blank()));
  38. }
  39. public function getInvalidValues()
  40. {
  41. return array(
  42. array('foobar'),
  43. array(0),
  44. array(false),
  45. array(1234),
  46. );
  47. }
  48. public function testMessageIsSet()
  49. {
  50. $constraint = new Blank(array(
  51. 'message' => 'myMessage'
  52. ));
  53. $this->assertFalse($this->validator->isValid('foobar', $constraint));
  54. $this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
  55. $this->assertEquals($this->validator->getMessageParameters(), array(
  56. '{{ value }}' => 'foobar',
  57. ));
  58. }
  59. }