NotNullValidatorTest.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Symfony\Tests\Component\Validator;
  3. use Symfony\Component\Validator\Constraints\NotNull;
  4. use Symfony\Component\Validator\Constraints\NotNullValidator;
  5. class NotNullValidatorTest extends \PHPUnit_Framework_TestCase
  6. {
  7. protected $validator;
  8. public function setUp()
  9. {
  10. $this->validator = new NotNullValidator();
  11. }
  12. /**
  13. * @dataProvider getValidValues
  14. */
  15. public function testValidValues($value)
  16. {
  17. $this->assertTrue($this->validator->isValid($value, new NotNull()));
  18. }
  19. public function getValidValues()
  20. {
  21. return array(
  22. array(0),
  23. array(false),
  24. array(true),
  25. array(''),
  26. );
  27. }
  28. public function testNullIsInvalid()
  29. {
  30. $constraint = new NotNull(array(
  31. 'message' => 'myMessage'
  32. ));
  33. $this->assertFalse($this->validator->isValid(null, $constraint));
  34. $this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
  35. $this->assertEquals($this->validator->getMessageParameters(), array());
  36. }
  37. }