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\Test\ConstraintValidatorTestCase;
19 class CurrencyValidatorTest extends ConstraintValidatorTestCase
21 protected function createValidator()
23 return new CurrencyValidator();
26 public function testNullIsValid()
28 $this->validator->validate(null, new Currency());
30 $this->assertNoViolation();
33 public function testEmptyStringIsValid()
35 $this->validator->validate('', new Currency());
37 $this->assertNoViolation();
41 * @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
43 public function testExpectsStringCompatibleType()
45 $this->validator->validate(new \stdClass(), new Currency());
49 * @dataProvider getValidCurrencies
51 public function testValidCurrencies($currency)
53 $this->validator->validate($currency, new Currency());
55 $this->assertNoViolation();
59 * @dataProvider getValidCurrencies
61 public function testValidCurrenciesWithCountrySpecificLocale($currency)
63 IntlTestHelper::requireFullIntl($this, false);
65 \Locale::setDefault('en_GB');
67 $this->validator->validate($currency, new Currency());
69 $this->assertNoViolation();
72 public function getValidCurrencies()
84 * @dataProvider getInvalidCurrencies
86 public function testInvalidCurrencies($currency)
88 $constraint = new Currency(array(
89 'message' => 'myMessage',
92 $this->validator->validate($currency, $constraint);
94 $this->buildViolation('myMessage')
95 ->setParameter('{{ value }}', '"'.$currency.'"')
96 ->setCode(Currency::NO_SUCH_CURRENCY_ERROR)
100 public function getInvalidCurrencies()