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\Validation;
18 class LocaleValidatorTest extends AbstractConstraintValidatorTest
20 protected function getApiVersion()
22 return Validation::API_VERSION_2_5;
25 protected function createValidator()
27 return new LocaleValidator();
30 public function testNullIsValid()
32 $this->validator->validate(null, new Locale());
34 $this->assertNoViolation();
37 public function testEmptyStringIsValid()
39 $this->validator->validate('', new Locale());
41 $this->assertNoViolation();
45 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
47 public function testExpectsStringCompatibleType()
49 $this->validator->validate(new \stdClass(), new Locale());
53 * @dataProvider getValidLocales
55 public function testValidLocales($locale)
57 $this->validator->validate($locale, new Locale());
59 $this->assertNoViolation();
62 public function getValidLocales()
75 * @dataProvider getInvalidLocales
77 public function testInvalidLocales($locale)
79 $constraint = new Locale(array(
80 'message' => 'myMessage',
83 $this->validator->validate($locale, $constraint);
85 $this->buildViolation('myMessage')
86 ->setParameter('{{ value }}', '"'.$locale.'"')
87 ->setCode(Locale::NO_SUCH_LOCALE_ERROR)
91 public function getInvalidLocales()