NotNullValidatorTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Constraints;
  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. protected function tearDown()
  21. {
  22. $this->validator = null;
  23. }
  24. /**
  25. * @dataProvider getValidValues
  26. */
  27. public function testValidValues($value)
  28. {
  29. $this->assertTrue($this->validator->isValid($value, new NotNull()));
  30. }
  31. public function getValidValues()
  32. {
  33. return array(
  34. array(0),
  35. array(false),
  36. array(true),
  37. array(''),
  38. );
  39. }
  40. public function testNullIsInvalid()
  41. {
  42. $constraint = new NotNull(array(
  43. 'message' => 'myMessage'
  44. ));
  45. $this->assertFalse($this->validator->isValid(null, $constraint));
  46. $this->assertEquals($this->validator->getMessageTemplate(), 'myMessage');
  47. $this->assertEquals($this->validator->getMessageParameters(), array());
  48. }
  49. }