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\Currency;
16 use Symfony\Component\Validator\Constraints\CurrencyValidator;
17 use Symfony\Component\Validator\Validation;
19 class CurrencyValidatorTest extends AbstractConstraintValidatorTest
21 protected function getApiVersion()
23 return Validation::API_VERSION_2_5;
26 protected function createValidator()
28 return new CurrencyValidator();
31 public function testNullIsValid()
33 $this->validator->validate(null, new Currency());
35 $this->assertNoViolation();
38 public function testEmptyStringIsValid()
40 $this->validator->validate('', new Currency());
42 $this->assertNoViolation();
46 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
48 public function testExpectsStringCompatibleType()
50 $this->validator->validate(new \stdClass(), new Currency());
54 * @dataProvider getValidCurrencies
56 public function testValidCurrencies($currency)
58 $this->validator->validate($currency, new Currency());
60 $this->assertNoViolation();
64 * @dataProvider getValidCurrencies
66 public function testValidCurrenciesWithCountrySpecificLocale($currency)
68 IntlTestHelper::requireFullIntl($this, false);
70 \Locale::setDefault('en_GB');
72 $this->validator->validate($currency, new Currency());
74 $this->assertNoViolation();
77 public function getValidCurrencies()
89 * @dataProvider getInvalidCurrencies
91 public function testInvalidCurrencies($currency)
93 $constraint = new Currency(array(
94 'message' => 'myMessage',
97 $this->validator->validate($currency, $constraint);
99 $this->buildViolation('myMessage')
100 ->setParameter('{{ value }}', '"'.$currency.'"')
101 ->setCode(Currency::NO_SUCH_CURRENCY_ERROR)
105 public function getInvalidCurrencies()