feb3c2f8e787ffd3f879e785c56e4e16e3acc4b9
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / NotNullValidatorTest.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\NotNull;
15 use Symfony\Component\Validator\Constraints\NotNullValidator;
16 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
17
18 class NotNullValidatorTest extends ConstraintValidatorTestCase
19 {
20     protected function createValidator()
21     {
22         return new NotNullValidator();
23     }
24
25     /**
26      * @dataProvider getValidValues
27      */
28     public function testValidValues($value)
29     {
30         $this->validator->validate($value, new NotNull());
31
32         $this->assertNoViolation();
33     }
34
35     public function getValidValues()
36     {
37         return array(
38             array(0),
39             array(false),
40             array(true),
41             array(''),
42         );
43     }
44
45     public function testNullIsInvalid()
46     {
47         $constraint = new NotNull(array(
48             'message' => 'myMessage',
49         ));
50
51         $this->validator->validate(null, $constraint);
52
53         $this->buildViolation('myMessage')
54             ->setParameter('{{ value }}', 'null')
55             ->setCode(NotNull::IS_NULL_ERROR)
56             ->assertRaised();
57     }
58 }