Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / RegexValidatorTest.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\Regex;
15 use Symfony\Component\Validator\Constraints\RegexValidator;
16 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
17
18 class RegexValidatorTest extends ConstraintValidatorTestCase
19 {
20     protected function createValidator()
21     {
22         return new RegexValidator();
23     }
24
25     public function testNullIsValid()
26     {
27         $this->validator->validate(null, new Regex(array('pattern' => '/^[0-9]+$/')));
28
29         $this->assertNoViolation();
30     }
31
32     public function testEmptyStringIsValid()
33     {
34         $this->validator->validate('', new Regex(array('pattern' => '/^[0-9]+$/')));
35
36         $this->assertNoViolation();
37     }
38
39     /**
40      * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
41      */
42     public function testExpectsStringCompatibleType()
43     {
44         $this->validator->validate(new \stdClass(), new Regex(array('pattern' => '/^[0-9]+$/')));
45     }
46
47     /**
48      * @dataProvider getValidValues
49      */
50     public function testValidValues($value)
51     {
52         $constraint = new Regex(array('pattern' => '/^[0-9]+$/'));
53         $this->validator->validate($value, $constraint);
54
55         $this->assertNoViolation();
56     }
57
58     public function getValidValues()
59     {
60         return array(
61             array(0),
62             array('0'),
63             array('090909'),
64             array(90909),
65         );
66     }
67
68     /**
69      * @dataProvider getInvalidValues
70      */
71     public function testInvalidValues($value)
72     {
73         $constraint = new Regex(array(
74             'pattern' => '/^[0-9]+$/',
75             'message' => 'myMessage',
76         ));
77
78         $this->validator->validate($value, $constraint);
79
80         $this->buildViolation('myMessage')
81             ->setParameter('{{ value }}', '"'.$value.'"')
82             ->setCode(Regex::REGEX_FAILED_ERROR)
83             ->assertRaised();
84     }
85
86     public function getInvalidValues()
87     {
88         return array(
89             array('abcd'),
90             array('090foo'),
91         );
92     }
93 }