Make unit tests working

This commit is contained in:
Eric Espie
2025-10-02 09:48:22 +02:00
parent 0ea0da525e
commit 39fd879ca9
83 changed files with 1924 additions and 262 deletions

View File

@@ -42,7 +42,7 @@ class FormValidator extends ConstraintValidator
return;
}
/* @var FormInterface $form */
/** @var FormInterface $form */
$config = $form->getConfig();
$validator = $this->context->getValidator()->inContext($this->context);
@@ -95,7 +95,7 @@ class FormValidator extends ConstraintValidator
$fieldFormConstraint = new Form();
$fieldFormConstraint->groups = $group;
$this->context->setNode($this->context->getValue(), $field, $this->context->getMetadata(), $this->context->getPropertyPath());
$validator->atPath(sprintf('children[%s]', $field->getName()))->validate($field, $fieldFormConstraint, $group);
$validator->atPath(\sprintf('children[%s]', $field->getName()))->validate($field, $fieldFormConstraint, $group);
}
}
@@ -142,7 +142,7 @@ class FormValidator extends ConstraintValidator
if ($field->isSubmitted()) {
$this->resolvedGroups[$field] = $groups;
$this->context->setNode($this->context->getValue(), $field, $this->context->getMetadata(), $this->context->getPropertyPath());
$validator->atPath(sprintf('children[%s]', $field->getName()))->validate($field, $formConstraint);
$validator->atPath(\sprintf('children[%s]', $field->getName()))->validate($field, $formConstraint);
}
}
}
@@ -159,7 +159,7 @@ class FormValidator extends ConstraintValidator
if (!$child->isSynchronized()) {
$childrenSynchronized = false;
$this->context->setNode($this->context->getValue(), $child, $this->context->getMetadata(), $this->context->getPropertyPath());
$validator->atPath(sprintf('children[%s]', $child->getName()))->validate($child, $formConstraint);
$validator->atPath(\sprintf('children[%s]', $child->getName()))->validate($child, $formConstraint);
}
}

View File

@@ -36,6 +36,7 @@ class ValidatorExtension extends AbstractExtension
{
$this->legacyErrorMessages = $legacyErrorMessages;
/** @var ClassMetadata $metadata */
$metadata = $validator->getMetadataFor(\Symfony\Component\Form\Form::class);
// Register the form constraints in the validator programmatically.
@@ -43,7 +44,6 @@ class ValidatorExtension extends AbstractExtension
// the DIC, where the XML file is loaded automatically. Thus the following
// code must be kept synchronized with validation.xml
/* @var $metadata ClassMetadata */
$metadata->addConstraint(new Form());
$metadata->addConstraint(new Traverse(false));

View File

@@ -232,7 +232,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
switch ($constraint::class) {
case Length::class:
if (is_numeric($constraint->min)) {
return new ValueGuess(sprintf('.{%s,}', (string) $constraint->min), Guess::LOW_CONFIDENCE);
return new ValueGuess(\sprintf('.{%s,}', (string) $constraint->min), Guess::LOW_CONFIDENCE);
}
break;
@@ -246,7 +246,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
case Range::class:
if (is_numeric($constraint->min)) {
return new ValueGuess(sprintf('.{%s,}', \strlen((string) $constraint->min)), Guess::LOW_CONFIDENCE);
return new ValueGuess(\sprintf('.{%s,}', \strlen((string) $constraint->min)), Guess::LOW_CONFIDENCE);
}
break;

View File

@@ -68,7 +68,7 @@ class MappingRule
foreach ($childNames as $childName) {
if (!$target->has($childName)) {
throw new ErrorMappingException(sprintf('The child "%s" of "%s" mapped by the rule "%s" in "%s" does not exist.', $childName, $target->getName(), $this->targetPath, $this->origin->getName()));
throw new ErrorMappingException(\sprintf('The child "%s" of "%s" mapped by the rule "%s" in "%s" does not exist.', $childName, $target->getName(), $this->targetPath, $this->origin->getName()));
}
$target = $target->get($childName);
}

View File

@@ -253,7 +253,7 @@ class ViolationMapper implements ViolationMapperInterface
// Test mapping rules as long as we have any
foreach ($rules as $key => $rule) {
/* @var MappingRule $rule */
/** @var MappingRule $rule */
// Mapping rule matches completely, terminate.
if (null !== ($form = $rule->match($chunk))) {
@@ -317,7 +317,7 @@ class ViolationMapper implements ViolationMapperInterface
// Cut the piece out of the property path and proceed
$propertyPathBuilder->remove($i);
} else {
/* @var \Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath */
/** @var \Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath */
$propertyPath = $scope->getPropertyPath();
if (null === $propertyPath) {

View File

@@ -132,7 +132,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function getElement(int $index): string
{
if (!isset($this->elements[$index])) {
throw new OutOfBoundsException(sprintf('The index "%s" is not within the violation path.', $index));
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the violation path.', $index));
}
return $this->elements[$index];
@@ -141,7 +141,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function isProperty(int $index): bool
{
if (!isset($this->isIndex[$index])) {
throw new OutOfBoundsException(sprintf('The index "%s" is not within the violation path.', $index));
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the violation path.', $index));
}
return !$this->isIndex[$index];
@@ -150,7 +150,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function isIndex(int $index): bool
{
if (!isset($this->isIndex[$index])) {
throw new OutOfBoundsException(sprintf('The index "%s" is not within the violation path.', $index));
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the violation path.', $index));
}
return $this->isIndex[$index];
@@ -176,7 +176,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
public function mapsForm(int $index): bool
{
if (!isset($this->mapsForm[$index])) {
throw new OutOfBoundsException(sprintf('The index "%s" is not within the violation path.', $index));
throw new OutOfBoundsException(\sprintf('The index "%s" is not within the violation path.', $index));
}
return $this->mapsForm[$index];