Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
psa
/
admin
/
plib
/
modules
/
wp-toolkit
/
vendor
/
symfony
/
validator
/
Test
/
File Content:
CompoundConstraintTestCase.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 WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\Test; use WPToolkitDependenciesIsolationPrefix\PHPUnit\Framework\ExpectationFailedException; use WPToolkitDependenciesIsolationPrefix\PHPUnit\Framework\TestCase; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\Constraint; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\Constraints\Compound; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\Constraints\CompoundValidator; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\ConstraintViolationListInterface; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\Context\ExecutionContext; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\Context\ExecutionContextInterface; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\Validation; use WPToolkitDependenciesIsolationPrefix\Symfony\Component\Validator\Validator\ValidatorInterface; use WPToolkitDependenciesIsolationPrefix\Symfony\Contracts\Translation\TranslatorInterface; /** * A test case to ease testing Compound Constraints. * * @author Alexandre Daubois <alex.daubois@gmail.com> * * @template T of Compound */ abstract class CompoundConstraintTestCase extends TestCase { protected ValidatorInterface $validator; protected ?ConstraintViolationListInterface $violationList = null; protected ExecutionContextInterface $context; protected string $root; private mixed $validatedValue; protected function setUp() : void { $this->root = 'root'; $this->validator = $this->createValidator(); $this->context = $this->createContext($this->validator); } protected function validateValue(mixed $value) : void { $this->validator->inContext($this->context)->validate($this->validatedValue = $value, $this->createCompound()); } protected function createValidator() : ValidatorInterface { return Validation::createValidator(); } protected function createContext(?ValidatorInterface $validator = null) : ExecutionContextInterface { $translator = $this->createMock(TranslatorInterface::class); $translator->expects($this->any())->method('trans')->willReturnArgument(0); return new ExecutionContext($validator ?? $this->createValidator(), $this->root, $translator); } public function assertViolationsRaisedByCompound(Constraint|array $constraints) : void { if ($constraints instanceof Constraint) { $constraints = [$constraints]; } $validator = new CompoundValidator(); $context = $this->createContext(); $validator->initialize($context); $validator->validate($this->validatedValue, new class($constraints) extends Compound { public function __construct(private array $testedConstraints) { parent::__construct(); } protected function getConstraints(array $options) : array { return $this->testedConstraints; } }); $expectedViolations = \iterator_to_array($context->getViolations()); if (!$expectedViolations) { throw new ExpectationFailedException(\sprintf('Expected at least one violation for constraint(s) "%s", got none raised.', \implode(', ', \array_map(fn($constraint) => $constraint::class, $constraints)))); } $failedToAssertViolations = []; \reset($expectedViolations); foreach ($this->context->getViolations() as $violation) { if ($violation != \current($expectedViolations)) { $failedToAssertViolations[] = $violation; } \next($expectedViolations); } $this->assertSame([], $failedToAssertViolations, \sprintf('Expected violation(s) for constraint(s) %s to be raised by compound.', \implode(', ', \array_map(fn($violation) => $violation->getConstraint()::class, $failedToAssertViolations)))); } public function assertViolationsCount(int $count) : void { $this->assertCount($count, $this->context->getViolations()); } protected function assertNoViolation() : void { $violationsCount = \count($this->context->getViolations()); $this->assertSame(0, $violationsCount, \sprintf('No violation expected. Got %d.', $violationsCount)); } /** * @return T */ protected abstract function createCompound() : Compound; }
Edit
Rename
Chmod
Delete
FILE
FOLDER
INFO
Name
Size
Permission
Action
CompoundConstraintTestCase.php
4774 bytes
0644
ConstraintValidatorTestCase.php
19047 bytes
0644
N4ST4R_ID | Naxtarrr