NullValidatorTest.php 1.4 KB

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