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\Validation;
18 class IsTrueValidatorTest extends AbstractConstraintValidatorTest
20 protected function getApiVersion()
22 return Validation::API_VERSION_2_5;
25 protected function createValidator()
27 return new IsTrueValidator();
30 public function testNullIsValid()
32 $this->validator->validate(null, new IsTrue());
34 $this->assertNoViolation();
37 public function testTrueIsValid()
39 $this->validator->validate(true, new IsTrue());
41 $this->assertNoViolation();
44 public function testFalseIsInvalid()
46 $constraint = new IsTrue(array(
47 'message' => 'myMessage',
50 $this->validator->validate(false, $constraint);
52 $this->buildViolation('myMessage')
53 ->setParameter('{{ value }}', 'false')
54 ->setCode(IsTrue::NOT_TRUE_ERROR)