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\IsNull;
15 use Symfony\Component\Validator\Constraints\IsNullValidator;
16 use Symfony\Component\Validator\Validation;
18 class IsNullValidatorTest extends AbstractConstraintValidatorTest
20 protected function getApiVersion()
22 return Validation::API_VERSION_2_5;
25 protected function createValidator()
27 return new IsNullValidator();
30 public function testNullIsValid()
32 $this->validator->validate(null, new IsNull());
34 $this->assertNoViolation();
38 * @dataProvider getInvalidValues
40 public function testInvalidValues($value, $valueAsString)
42 $constraint = new IsNull(array(
43 'message' => 'myMessage',
46 $this->validator->validate($value, $constraint);
48 $this->buildViolation('myMessage')
49 ->setParameter('{{ value }}', $valueAsString)
50 ->setCode(IsNull::NOT_NULL_ERROR)
54 public function getInvalidValues()
58 array(false, 'false'),
61 array('foo bar', '"foo bar"'),
62 array(new \DateTime(), 'object'),
63 array(new \stdClass(), 'object'),
64 array(array(), 'array'),