IsFalseValidatorTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\Component\Validator\Tests\Constraints;
  11. use Symfony\Component\Validator\Constraints\IsFalse;
  12. use Symfony\Component\Validator\Constraints\IsFalseValidator;
  13. use Symfony\Component\Validator\Validation;
  14. class IsFalseValidatorTest extends AbstractConstraintValidatorTest
  15. {
  16. protected function getApiVersion()
  17. {
  18. return Validation::API_VERSION_2_5;
  19. }
  20. protected function createValidator()
  21. {
  22. return new IsFalseValidator();
  23. }
  24. public function testNullIsValid()
  25. {
  26. $this->validator->validate(null, new IsFalse());
  27. $this->assertNoViolation();
  28. }
  29. public function testFalseIsValid()
  30. {
  31. $this->validator->validate(false, new IsFalse());
  32. $this->assertNoViolation();
  33. }
  34. public function testTrueIsInvalid()
  35. {
  36. $constraint = new IsFalse(array(
  37. 'message' => 'myMessage',
  38. ));
  39. $this->validator->validate(true, $constraint);
  40. $this->buildViolation('myMessage')
  41. ->setParameter('{{ value }}', 'true')
  42. ->setCode(IsFalse::NOT_FALSE_ERROR)
  43. ->assertRaised();
  44. }
  45. }