NotNullValidatorTest.php 1.1 KB

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