NotBlankValidatorTest.php 1.6 KB

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