NotNullValidatorTest.php 1.3 KB

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