1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Validator\Tests\Constraints;
13
14use Symfony\Component\Validator\Constraints\IsTrue;
15use Symfony\Component\Validator\Constraints\IsTrueValidator;
16use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
17
18class IsTrueValidatorTest extends ConstraintValidatorTestCase
19{
20    protected function createValidator()
21    {
22        return new IsTrueValidator();
23    }
24
25    public function testNullIsValid()
26    {
27        $this->validator->validate(null, new IsTrue());
28
29        $this->assertNoViolation();
30    }
31
32    public function testTrueIsValid()
33    {
34        $this->validator->validate(true, new IsTrue());
35
36        $this->assertNoViolation();
37    }
38
39    public function testFalseIsInvalid()
40    {
41        $constraint = new IsTrue([
42            'message' => 'myMessage',
43        ]);
44
45        $this->validator->validate(false, $constraint);
46
47        $this->buildViolation('myMessage')
48            ->setParameter('{{ value }}', 'false')
49            ->setCode(IsTrue::NOT_TRUE_ERROR)
50            ->assertRaised();
51    }
52}
53