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\Blank;
15use Symfony\Component\Validator\Constraints\BlankValidator;
16use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
17
18class BlankValidatorTest extends ConstraintValidatorTestCase
19{
20    protected function createValidator()
21    {
22        return new BlankValidator();
23    }
24
25    public function testNullIsValid()
26    {
27        $this->validator->validate(null, new Blank());
28
29        $this->assertNoViolation();
30    }
31
32    public function testBlankIsValid()
33    {
34        $this->validator->validate('', new Blank());
35
36        $this->assertNoViolation();
37    }
38
39    /**
40     * @dataProvider getInvalidValues
41     */
42    public function testInvalidValues($value, $valueAsString)
43    {
44        $constraint = new Blank([
45            'message' => 'myMessage',
46        ]);
47
48        $this->validator->validate($value, $constraint);
49
50        $this->buildViolation('myMessage')
51            ->setParameter('{{ value }}', $valueAsString)
52            ->setCode(Blank::NOT_BLANK_ERROR)
53            ->assertRaised();
54    }
55
56    public function getInvalidValues()
57    {
58        return [
59            ['foobar', '"foobar"'],
60            [0, '0'],
61            [false, 'false'],
62            [1234, '1234'],
63        ];
64    }
65}
66