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\Locale;
15 use Symfony\Component\Validator\Constraints\LocaleValidator;
16 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
18 class LocaleValidatorTest extends ConstraintValidatorTestCase
20 protected function createValidator()
22 return new LocaleValidator();
25 public function testNullIsValid()
27 $this->validator->validate(null, new Locale());
29 $this->assertNoViolation();
32 public function testEmptyStringIsValid()
34 $this->validator->validate('', new Locale());
36 $this->assertNoViolation();
40 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
42 public function testExpectsStringCompatibleType()
44 $this->validator->validate(new \stdClass(), new Locale());
48 * @dataProvider getValidLocales
50 public function testValidLocales($locale)
52 $this->validator->validate($locale, new Locale());
54 $this->assertNoViolation();
57 public function getValidLocales()
70 * @dataProvider getInvalidLocales
72 public function testInvalidLocales($locale)
74 $constraint = new Locale(array(
75 'message' => 'myMessage',
78 $this->validator->validate($locale, $constraint);
80 $this->buildViolation('myMessage')
81 ->setParameter('{{ value }}', '"'.$locale.'"')
82 ->setCode(Locale::NO_SUCH_LOCALE_ERROR)
86 public function getInvalidLocales()