Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function validate(mixed $value, Constraint $constraint)
throw new UnexpectedTypeException($constraint, Length::class);
}

if (null === $value) {
if (null === $value || '' === $value) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,11 @@ public function testNullIsValid()
$this->assertNoViolation();
}

public function testEmptyStringIsInvalid()
public function testEmptyStringIsValid()
{
$this->validator->validate('', new Length([
'value' => $limit = 6,
'exactMessage' => 'myMessage',
]));
$this->validator->validate('', new Length(['value' => 6]));

$this->buildViolation('myMessage')
->setParameter('{{ value }}', '""')
->setParameter('{{ limit }}', $limit)
->setInvalidValue('')
->setPlural($limit)
->setCode(Length::NOT_EQUAL_LENGTH_ERROR)
->assertRaised();
$this->assertNoViolation();
}

public function testExpectsStringCompatibleType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2202,10 +2202,9 @@ public function testAllConstraintValidateAllGroupsForNestedConstraints()

$violations = $this->validator->validate($entity, null, ['one', 'two']);

$this->assertCount(3, $violations);
$this->assertCount(2, $violations);
$this->assertInstanceOf(NotBlank::class, $violations->get(0)->getConstraint());
$this->assertInstanceOf(Length::class, $violations->get(1)->getConstraint());
$this->assertInstanceOf(Length::class, $violations->get(2)->getConstraint());
}

public function testRequiredConstraintIsIgnored()
Expand Down