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\Intl\Util\IntlTestHelper;
15 use Symfony\Component\Validator\Constraints\Country;
16 use Symfony\Component\Validator\Constraints\CountryValidator;
17 use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
19 class CountryValidatorTest extends ConstraintValidatorTestCase
21 protected function createValidator()
23 return new CountryValidator();
26 public function testNullIsValid()
28 $this->validator->validate(null, new Country());
30 $this->assertNoViolation();
33 public function testEmptyStringIsValid()
35 $this->validator->validate('', new Country());
37 $this->assertNoViolation();
41 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
43 public function testExpectsStringCompatibleType()
45 $this->validator->validate(new \stdClass(), new Country());
49 * @dataProvider getValidCountries
51 public function testValidCountries($country)
53 $this->validator->validate($country, new Country());
55 $this->assertNoViolation();
58 public function getValidCountries()
68 * @dataProvider getInvalidCountries
70 public function testInvalidCountries($country)
72 $constraint = new Country(array(
73 'message' => 'myMessage',
76 $this->validator->validate($country, $constraint);
78 $this->buildViolation('myMessage')
79 ->setParameter('{{ value }}', '"'.$country.'"')
80 ->setCode(Country::NO_SUCH_COUNTRY_ERROR)
84 public function getInvalidCountries()
92 public function testValidateUsingCountrySpecificLocale()
94 // in order to test with "en_GB"
95 IntlTestHelper::requireFullIntl($this, false);
97 \Locale::setDefault('en_GB');
99 $existingCountry = 'GB';
101 $this->validator->validate($existingCountry, new Country());
103 $this->assertNoViolation();