4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Validator\Tests\Constraints;
14 use Symfony\Component\Validator\Constraints\IsTrue;
15 use Symfony\Component\Validator\Constraints\IsTrueValidator;
16 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
18 class IsTrueValidatorTest extends ConstraintValidatorTestCase
20 protected function createValidator()
22 return new IsTrueValidator();
25 public function testNullIsValid()
27 $this->validator->validate(null, new IsTrue());
29 $this->assertNoViolation();
32 public function testTrueIsValid()
34 $this->validator->validate(true, new IsTrue());
36 $this->assertNoViolation();
39 public function testFalseIsInvalid()
41 $constraint = new IsTrue(array(
42 'message' => 'myMessage',
45 $this->validator->validate(false, $constraint);
47 $this->buildViolation('myMessage')
48 ->setParameter('{{ value }}', 'false')
49 ->setCode(IsTrue::NOT_TRUE_ERROR)