Skip to content

Commit f14be6c

Browse files
committed
Ignore 'Valid'. There's no like-for-like
1 parent 4be66c5 commit f14be6c

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/Factory/ConstraintFactory.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@ class ConstraintFactory
2929
/**
3030
* @param Constraint $validationConstraint
3131
* @param FormInterface $form
32-
* @return ConstraintInterface
32+
* @return ConstraintInterface|null
3333
* @throws \Exception
3434
* @throws \InvalidArgumentException
3535
* @throws \RuntimeException
3636
*/
3737
public static function createFromValidationConstraint(
3838
Constraint $validationConstraint,
3939
FormInterface $form
40-
): ConstraintInterface {
40+
): ?ConstraintInterface {
4141
// TODO Change this to use the ViewInterface instead of the FormInterface as that makes a lot more sense!
4242

43-
if ($validationConstraint instanceof \Symfony\Component\Validator\Constraints\NotNull) {
43+
if ($validationConstraint instanceof \Symfony\Component\Validator\Constraints\Valid) {
44+
// This case is not an error. There just isn't a 'like-for-like' replacement
45+
return null;
46+
} elseif ($validationConstraint instanceof \Symfony\Component\Validator\Constraints\NotNull) {
4447
return new Required($validationConstraint->message);
4548
} elseif ($validationConstraint instanceof \Symfony\Component\Validator\Constraints\NotBlank) {
4649
return new Required($validationConstraint->message);

src/Form/Extension/ParsleyTypeExtension.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ private function createParsleyConstraintsFromValidationConstraints(
100100
$out = [];
101101
foreach ($validationConstraints as $validationConstraint) {
102102
try {
103-
$out[] = ConstraintFactory::createFromValidationConstraint($validationConstraint, $form);
103+
$parsleyConstraint = ConstraintFactory::createFromValidationConstraint($validationConstraint, $form);
104+
if ($parsleyConstraint !== null) {
105+
$out[] = $parsleyConstraint;
106+
}
104107
} catch (\RuntimeException $exception) {
105108
// Don't care for now!
106109
// TODO How loud this should be should be configurable

tests/Factory/ConstraintFactoryTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Validator\Constraints\NotBlank;
2424
use Symfony\Component\Validator\Constraints\NotNull;
2525
use Symfony\Component\Validator\Constraints\Regex;
26+
use Symfony\Component\Validator\Constraints\Valid;
2627
use Symfony\Component\Validator\ConstraintViolationList;
2728
use Symfony\Component\Validator\Mapping\ClassMetadata;
2829
use Symfony\Component\Validator\Validator\ValidatorInterface;
@@ -66,6 +67,12 @@ public function getFactoryTestData()
6667
$form = $factory->create(TestType::class, null, []);
6768

6869
return [
70+
[
71+
new Valid(),
72+
$form->get('id'),
73+
null,
74+
'Valid to Null',
75+
],
6976
[
7077
new NotNull(['message' => 'Give me something']),
7178
$form->get('id'),

0 commit comments

Comments
 (0)