Skip to content

Commit f7f4d4a

Browse files
Merge branch '5.4' into 6.0
* 5.4: [PropertyAccess] Fix handling of uninitialized property of parent class [DomCrawler] ignore bad charsets [Validator] Fix minRatio and maxRatio when getting rounded [Console] Revert StringInput bc break from #45088 [Form] Do not fix URL protocol for relative URLs [Serializer] make XmlEncoder stateless thus reentrant
2 parents 35f3614 + 11a17d9 commit f7f4d4a

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

Constraints/ImageValidator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ public function validate(mixed $value, Constraint $constraint)
169169
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum ratio.', $constraint->minRatio));
170170
}
171171

172-
if ($ratio < $constraint->minRatio) {
172+
if ($ratio < round($constraint->minRatio, 2)) {
173173
$this->context->buildViolation($constraint->minRatioMessage)
174174
->setParameter('{{ ratio }}', $ratio)
175-
->setParameter('{{ min_ratio }}', $constraint->minRatio)
175+
->setParameter('{{ min_ratio }}', round($constraint->minRatio, 2))
176176
->setCode(Image::RATIO_TOO_SMALL_ERROR)
177177
->addViolation();
178178
}
@@ -183,10 +183,10 @@ public function validate(mixed $value, Constraint $constraint)
183183
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum ratio.', $constraint->maxRatio));
184184
}
185185

186-
if ($ratio > $constraint->maxRatio) {
186+
if ($ratio > round($constraint->maxRatio, 2)) {
187187
$this->context->buildViolation($constraint->maxRatioMessage)
188188
->setParameter('{{ ratio }}', $ratio)
189-
->setParameter('{{ max_ratio }}', $constraint->maxRatio)
189+
->setParameter('{{ max_ratio }}', round($constraint->maxRatio, 2))
190190
->setCode(Image::RATIO_TOO_BIG_ERROR)
191191
->addViolation();
192192
}
102 Bytes
Loading

Tests/Constraints/ImageValidatorTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected function setUp(): void
4848
$this->imageLandscape = __DIR__.'/Fixtures/test_landscape.gif';
4949
$this->imagePortrait = __DIR__.'/Fixtures/test_portrait.gif';
5050
$this->image4By3 = __DIR__.'/Fixtures/test_4by3.gif';
51+
$this->image16By9 = __DIR__.'/Fixtures/test_16by9.gif';
5152
$this->imageCorrupted = __DIR__.'/Fixtures/test_corrupted.gif';
5253
}
5354

@@ -386,6 +387,28 @@ public function testMaxRatioUsesTwoDecimalsOnly()
386387
$this->assertNoViolation();
387388
}
388389

390+
public function testMinRatioUsesInputMoreDecimals()
391+
{
392+
$constraint = new Image([
393+
'minRatio' => 4 / 3,
394+
]);
395+
396+
$this->validator->validate($this->image4By3, $constraint);
397+
398+
$this->assertNoViolation();
399+
}
400+
401+
public function testMaxRatioUsesInputMoreDecimals()
402+
{
403+
$constraint = new Image([
404+
'maxRatio' => 16 / 9,
405+
]);
406+
407+
$this->validator->validate($this->image16By9, $constraint);
408+
409+
$this->assertNoViolation();
410+
}
411+
389412
public function testInvalidMinRatio()
390413
{
391414
$this->expectException(ConstraintDefinitionException::class);

0 commit comments

Comments
 (0)