
| Current Path : /var/www/html/ift/vendor/symfony/validator/Tests/Constraints/ |
Linux ift1.ift-informatik.de 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 |
| Current File : /var/www/html/ift/vendor/symfony/validator/Tests/Constraints/LocaleValidatorTest.php |
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Validator\Tests\Constraints;
use Symfony\Component\Validator\Constraints\Locale;
use Symfony\Component\Validator\Constraints\LocaleValidator;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
class LocaleValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator()
{
return new LocaleValidator();
}
public function testNullIsValid()
{
$this->validator->validate(null, new Locale());
$this->assertNoViolation();
}
public function testEmptyStringIsValid()
{
$this->validator->validate('', new Locale());
$this->assertNoViolation();
}
public function testExpectsStringCompatibleType()
{
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
$this->validator->validate(new \stdClass(), new Locale());
}
/**
* @dataProvider getValidLocales
*/
public function testValidLocales($locale)
{
$this->validator->validate($locale, new Locale());
$this->assertNoViolation();
}
public function getValidLocales()
{
return [
['en'],
['en_US'],
['pt'],
['pt_PT'],
['zh_Hans'],
['fil_PH'],
];
}
/**
* @dataProvider getInvalidLocales
*/
public function testInvalidLocales($locale)
{
$constraint = new Locale([
'message' => 'myMessage',
]);
$this->validator->validate($locale, $constraint);
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"'.$locale.'"')
->setCode(Locale::NO_SUCH_LOCALE_ERROR)
->assertRaised();
}
public function getInvalidLocales()
{
return [
['EN'],
['foobar'],
];
}
}