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\Validation;
18 class NotBlankValidatorTest extends AbstractConstraintValidatorTest
20 protected function getApiVersion()
22 return Validation::API_VERSION_2_5;
25 protected function createValidator()
27 return new NotBlankValidator();
31 * @dataProvider getValidValues
33 public function testValidValues($value)
35 $this->validator->validate($value, new NotBlank());
37 $this->assertNoViolation();
40 public function getValidValues()
51 public function testNullIsInvalid()
53 $constraint = new NotBlank(array(
54 'message' => 'myMessage',
57 $this->validator->validate(null, $constraint);
59 $this->buildViolation('myMessage')
60 ->setParameter('{{ value }}', 'null')
61 ->setCode(NotBlank::IS_BLANK_ERROR)
65 public function testBlankIsInvalid()
67 $constraint = new NotBlank(array(
68 'message' => 'myMessage',
71 $this->validator->validate('', $constraint);
73 $this->buildViolation('myMessage')
74 ->setParameter('{{ value }}', '""')
75 ->setCode(NotBlank::IS_BLANK_ERROR)
79 public function testFalseIsInvalid()
81 $constraint = new NotBlank(array(
82 'message' => 'myMessage',
85 $this->validator->validate(false, $constraint);
87 $this->buildViolation('myMessage')
88 ->setParameter('{{ value }}', 'false')
89 ->setCode(NotBlank::IS_BLANK_ERROR)
93 public function testEmptyArrayIsInvalid()
95 $constraint = new NotBlank(array(
96 'message' => 'myMessage',
99 $this->validator->validate(array(), $constraint);
101 $this->buildViolation('myMessage')
102 ->setParameter('{{ value }}', 'array')
103 ->setCode(NotBlank::IS_BLANK_ERROR)