5a5575313b7319304d069bde8e78f5003453cee4
[yaffs-website] / Tests / Constraints / IsNullValidatorTest.php
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
12 namespace Symfony\Component\Validator\Tests\Constraints;
13
14 use Symfony\Component\Validator\Constraints\IsNull;
15 use Symfony\Component\Validator\Constraints\IsNullValidator;
16 use Symfony\Component\Validator\Validation;
17
18 class IsNullValidatorTest extends AbstractConstraintValidatorTest
19 {
20     protected function getApiVersion()
21     {
22         return Validation::API_VERSION_2_5;
23     }
24
25     protected function createValidator()
26     {
27         return new IsNullValidator();
28     }
29
30     public function testNullIsValid()
31     {
32         $this->validator->validate(null, new IsNull());
33
34         $this->assertNoViolation();
35     }
36
37     /**
38      * @dataProvider getInvalidValues
39      */
40     public function testInvalidValues($value, $valueAsString)
41     {
42         $constraint = new IsNull(array(
43             'message' => 'myMessage',
44         ));
45
46         $this->validator->validate($value, $constraint);
47
48         $this->buildViolation('myMessage')
49             ->setParameter('{{ value }}', $valueAsString)
50             ->setCode(IsNull::NOT_NULL_ERROR)
51             ->assertRaised();
52     }
53
54     public function getInvalidValues()
55     {
56         return array(
57             array(0, '0'),
58             array(false, 'false'),
59             array(true, 'true'),
60             array('', '""'),
61             array('foo bar', '"foo bar"'),
62             array(new \DateTime(), 'object'),
63             array(new \stdClass(), 'object'),
64             array(array(), 'array'),
65         );
66     }
67 }