Yaffs site version 1.1
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / BlankValidatorTest.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\Blank;
15 use Symfony\Component\Validator\Constraints\BlankValidator;
16 use Symfony\Component\Validator\Validation;
17
18 class BlankValidatorTest 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 BlankValidator();
28     }
29
30     public function testNullIsValid()
31     {
32         $this->validator->validate(null, new Blank());
33
34         $this->assertNoViolation();
35     }
36
37     public function testBlankIsValid()
38     {
39         $this->validator->validate('', new Blank());
40
41         $this->assertNoViolation();
42     }
43
44     /**
45      * @dataProvider getInvalidValues
46      */
47     public function testInvalidValues($value, $valueAsString)
48     {
49         $constraint = new Blank(array(
50             'message' => 'myMessage',
51         ));
52
53         $this->validator->validate($value, $constraint);
54
55         $this->buildViolation('myMessage')
56             ->setParameter('{{ value }}', $valueAsString)
57             ->setCode(Blank::NOT_BLANK_ERROR)
58             ->assertRaised();
59     }
60
61     public function getInvalidValues()
62     {
63         return array(
64             array('foobar', '"foobar"'),
65             array(0, '0'),
66             array(false, 'false'),
67             array(1234, '1234'),
68         );
69     }
70 }