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\Regex;
15 use Symfony\Component\Validator\Constraints\RegexValidator;
16 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
18 class RegexValidatorTest extends ConstraintValidatorTestCase
20 protected function createValidator()
22 return new RegexValidator();
25 public function testNullIsValid()
27 $this->validator->validate(null, new Regex(array('pattern' => '/^[0-9]+$/')));
29 $this->assertNoViolation();
32 public function testEmptyStringIsValid()
34 $this->validator->validate('', new Regex(array('pattern' => '/^[0-9]+$/')));
36 $this->assertNoViolation();
40 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
42 public function testExpectsStringCompatibleType()
44 $this->validator->validate(new \stdClass(), new Regex(array('pattern' => '/^[0-9]+$/')));
48 * @dataProvider getValidValues
50 public function testValidValues($value)
52 $constraint = new Regex(array('pattern' => '/^[0-9]+$/'));
53 $this->validator->validate($value, $constraint);
55 $this->assertNoViolation();
58 public function getValidValues()
69 * @dataProvider getInvalidValues
71 public function testInvalidValues($value)
73 $constraint = new Regex(array(
74 'pattern' => '/^[0-9]+$/',
75 'message' => 'myMessage',
78 $this->validator->validate($value, $constraint);
80 $this->buildViolation('myMessage')
81 ->setParameter('{{ value }}', '"'.$value.'"')
82 ->setCode(Regex::REGEX_FAILED_ERROR)
86 public function getInvalidValues()