NotBlankValidatorTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Symfony\Tests\Components\Validator;
  3. require_once __DIR__.'/../../../../../bootstrap.php';
  4. use Symfony\Components\Validator\Constraints\NotBlank;
  5. use Symfony\Components\Validator\Constraints\NotBlankValidator;
  6. class NotBlankValidatorTest extends \PHPUnit_Framework_TestCase
  7. {
  8. protected $validator;
  9. public function setUp()
  10. {
  11. $this->validator = new NotBlankValidator();
  12. }
  13. /**
  14. * @dataProvider getInvalidValues
  15. */
  16. public function testInvalidValues($date)
  17. {
  18. $this->assertTrue($this->validator->isValid($date, new NotBlank()));
  19. }
  20. public function getInvalidValues()
  21. {
  22. return array(
  23. array('foobar'),
  24. array(0),
  25. array(false),
  26. array(1234),
  27. );
  28. }
  29. public function testNullIsInvalid()
  30. {
  31. $this->assertFalse($this->validator->isValid(null, new NotBlank()));
  32. }
  33. public function testBlankIsInvalid()
  34. {
  35. $this->assertFalse($this->validator->isValid('', new NotBlank()));
  36. }
  37. public function testSetMessage()
  38. {
  39. $constraint = new NotBlank(array(
  40. 'message' => 'myMessage'
  41. ));
  42. $this->assertFalse($this->validator->isValid('', $constraint));
  43. $this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
  44. $this->assertEquals($this->validator->getMessageParameters(), array());
  45. }
  46. }