BlankValidatorTest.php 1.4 KB

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