/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Validator/Tests/ConstraintTest.php
85 строк
2 KB
Nicolas Grekas
Merge branch '7.4' into 8.0
06 мар 2026, 16:17
06 мар 2026, 16:17
d3aefbc
Код
Авторство
О чём код?
<?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; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Exception\InvalidArgumentException; use Symfony\Component\Validator\Tests\Fixtures\ClassConstraint; use Symfony\Component\Validator\Tests\Fixtures\ConstraintA; use Symfony\Component\Validator\Tests\Fixtures\CustomRegex; class ConstraintTest extends TestCase { public function testAddDefaultGroupAddsGroup() { $constraint = new ConstraintA(null, null, ['Default']); $constraint->addImplicitGroupName('Foo'); $this->assertEquals(['Default', 'Foo'], $constraint->groups); } public function testGetTargetsCanBeString() { $constraint = new ClassConstraint(); $this->assertEquals('class', $constraint->getTargets()); } public function testGetTargetsCanBeArray() { $constraint = new ConstraintA(); $this->assertEquals(['property', 'class'], $constraint->getTargets()); } public function testSerialize() { $constraint = new ConstraintA('foo', 'bar'); $restoredConstraint = unserialize(serialize($constraint)); $this->assertEquals($constraint, $restoredConstraint); } public function testSerializeInitializesGroupsOptionToDefault() { $constraint = new ConstraintA('foo', 'bar'); $constraint = unserialize(serialize($constraint)); $expected = new ConstraintA('foo', 'bar', ['Default']); $this->assertEquals($expected, $constraint); } public function testSerializeKeepsCustomGroups() { $constraint = new ConstraintA('foo', 'bar', ['MyGroup']); $constraint = unserialize(serialize($constraint)); $this->assertSame(['MyGroup'], $constraint->groups); } public function testGetErrorNameForUnknownCode() { $this->expectException(InvalidArgumentException::class); Constraint::getErrorName(1); } public function testChildConstraintCanSatisfyRequiredOptionsOfParent() { $constraint = new CustomRegex(); $this->assertSame('/^xxxxx$/', $constraint->pattern); } }