/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/Validator/Tests/Test/ConstraintValidatorTestCaseTest.php
79 строк
2 KB
Nicolas Grekas
Merge branch '8.0' into 8.1
22 июл 2026, 18:42
22 июл 2026, 18:42
e7681b1
Код
Авторство
О чём код?
<?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\Test; use PHPUnit\Framework\ExpectationFailedException; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\Constraints\DateTime; use Symfony\Component\Validator\Constraints\NotNull; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; class TestCustomValidator extends ConstraintValidator { public function validate($value, Constraint $constraint): void { $validator = $this->context ->getValidator() ->inContext($this->context); $validator ->atPath('k1') ->validate($value, [ new NotNull(), ]); } } class ConstraintValidatorTestCaseTest extends ConstraintValidatorTestCase { protected function createValidator(): TestCustomValidator { return new TestCustomValidator(); } public function testSetGroupAllowsNull() { $this->setGroup('Other'); $this->setGroup(null); $this->assertSame('Other', $this->group); $this->assertNull($this->context->getGroup()); } public function testAssertingContextualValidatorRemainingExpectationsThrow() { $this->expectValidateValueAt(0, 'k1', 'ccc', [ new NotNull(), ]); $this->expectValidateValueAt(1, 'k2', 'ccc', [ new DateTime(), ]); $this->validate('ccc', $this->constraint); $contextualValidator = $this->context->getValidator()->inContext($this->context); // Simulate __destruct to assert it throws try { $contextualValidator->__destruct(); $this->fail(); } catch (ExpectationFailedException $e) { } // Actually fulfill expectations so real __destruct doesn't throw $contextualValidator ->atPath('k2') ->validate('ccc', [ new DateTime(), ]); } }