Skip to content

Commit 11a17d9

Browse files
Merge branch '4.4' into 5.4
* 4.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 b420894 + 52ccd2e commit 11a17d9

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($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($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

@@ -413,6 +414,28 @@ public function testMaxRatioUsesTwoDecimalsOnly()
413414
$this->assertNoViolation();
414415
}
415416

417+
public function testMinRatioUsesInputMoreDecimals()
418+
{
419+
$constraint = new Image([
420+
'minRatio' => 4 / 3,
421+
]);
422+
423+
$this->validator->validate($this->image4By3, $constraint);
424+
425+
$this->assertNoViolation();
426+
}
427+
428+
public function testMaxRatioUsesInputMoreDecimals()
429+
{
430+
$constraint = new Image([
431+
'maxRatio' => 16 / 9,
432+
]);
433+
434+
$this->validator->validate($this->image16By9, $constraint);
435+
436+
$this->assertNoViolation();
437+
}
438+
416439
public function testInvalidMinRatio()
417440
{
418441
$this->expectException(ConstraintDefinitionException::class);

0 commit comments

Comments
 (0)