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\Validation;
19 class CountryValidatorTest extends AbstractConstraintValidatorTest
21 protected function getApiVersion()
23 return Validation::API_VERSION_2_5;
26 protected function createValidator()
28 return new CountryValidator();
31 public function testNullIsValid()
33 $this->validator->validate(null, new Country());
35 $this->assertNoViolation();
38 public function testEmptyStringIsValid()
40 $this->validator->validate('', new Country());
42 $this->assertNoViolation();
46 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
48 public function testExpectsStringCompatibleType()
50 $this->validator->validate(new \stdClass(), new Country());
54 * @dataProvider getValidCountries
56 public function testValidCountries($country)
58 $this->validator->validate($country, new Country());
60 $this->assertNoViolation();
63 public function getValidCountries()
73 * @dataProvider getInvalidCountries
75 public function testInvalidCountries($country)
77 $constraint = new Country(array(
78 'message' => 'myMessage',
81 $this->validator->validate($country, $constraint);
83 $this->buildViolation('myMessage')
84 ->setParameter('{{ value }}', '"'.$country.'"')
85 ->setCode(Country::NO_SUCH_COUNTRY_ERROR)
89 public function getInvalidCountries()
97 public function testValidateUsingCountrySpecificLocale()
99 // in order to test with "en_GB"
100 IntlTestHelper::requireFullIntl($this, false);
102 \Locale::setDefault('en_GB');
104 $existingCountry = 'GB';
106 $this->validator->validate($existingCountry, new Country());
108 $this->assertNoViolation();