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\NotBlank;
15 use Symfony\Component\Validator\Constraints\NotBlankValidator;
16 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
18 class NotBlankValidatorTest extends ConstraintValidatorTestCase
20 protected function createValidator()
22 return new NotBlankValidator();
26 * @dataProvider getValidValues
28 public function testValidValues($value)
30 $this->validator->validate($value, new NotBlank());
32 $this->assertNoViolation();
35 public function getValidValues()
46 public function testNullIsInvalid()
48 $constraint = new NotBlank(array(
49 'message' => 'myMessage',
52 $this->validator->validate(null, $constraint);
54 $this->buildViolation('myMessage')
55 ->setParameter('{{ value }}', 'null')
56 ->setCode(NotBlank::IS_BLANK_ERROR)
60 public function testBlankIsInvalid()
62 $constraint = new NotBlank(array(
63 'message' => 'myMessage',
66 $this->validator->validate('', $constraint);
68 $this->buildViolation('myMessage')
69 ->setParameter('{{ value }}', '""')
70 ->setCode(NotBlank::IS_BLANK_ERROR)
74 public function testFalseIsInvalid()
76 $constraint = new NotBlank(array(
77 'message' => 'myMessage',
80 $this->validator->validate(false, $constraint);
82 $this->buildViolation('myMessage')
83 ->setParameter('{{ value }}', 'false')
84 ->setCode(NotBlank::IS_BLANK_ERROR)
88 public function testEmptyArrayIsInvalid()
90 $constraint = new NotBlank(array(
91 'message' => 'myMessage',
94 $this->validator->validate(array(), $constraint);
96 $this->buildViolation('myMessage')
97 ->setParameter('{{ value }}', 'array')
98 ->setCode(NotBlank::IS_BLANK_ERROR)