Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] Fix minRatio and maxRatio when getting rounded #45204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2022
Merged
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
[Validator] Fix minRatio and maxRatio when getting rounded
  • Loading branch information
alexander-schranz authored and fancyweb committed Jan 31, 2022
commit 0f85ba030b8725642ed0fdef804e969d88fcd7e5
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ public function validate($value, Constraint $constraint)
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid minimum ratio.', $constraint->minRatio));
}

if ($ratio < $constraint->minRatio) {
if ($ratio < round($constraint->minRatio, 2)) {
$this->context->buildViolation($constraint->minRatioMessage)
->setParameter('{{ ratio }}', $ratio)
->setParameter('{{ min_ratio }}', $constraint->minRatio)
->setParameter('{{ min_ratio }}', round($constraint->minRatio, 2))
->setCode(Image::RATIO_TOO_SMALL_ERROR)
->addViolation();
}
Expand All @@ -183,10 +183,10 @@ public function validate($value, Constraint $constraint)
throw new ConstraintDefinitionException(sprintf('"%s" is not a valid maximum ratio.', $constraint->maxRatio));
}

if ($ratio > $constraint->maxRatio) {
if ($ratio > round($constraint->maxRatio, 2)) {
$this->context->buildViolation($constraint->maxRatioMessage)
->setParameter('{{ ratio }}', $ratio)
->setParameter('{{ max_ratio }}', $constraint->maxRatio)
->setParameter('{{ max_ratio }}', round($constraint->maxRatio, 2))
->setCode(Image::RATIO_TOO_BIG_ERROR)
->addViolation();
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected function setUp(): void
$this->imageLandscape = __DIR__.'/Fixtures/test_landscape.gif';
$this->imagePortrait = __DIR__.'/Fixtures/test_portrait.gif';
$this->image4By3 = __DIR__.'/Fixtures/test_4by3.gif';
$this->image16By9 = __DIR__.'/Fixtures/test_16by9.gif';
$this->imageCorrupted = __DIR__.'/Fixtures/test_corrupted.gif';
}

Expand Down Expand Up @@ -304,6 +305,28 @@ public function testMaxRatioUsesTwoDecimalsOnly()
$this->assertNoViolation();
}

public function testMinRatioUsesInputMoreDecimals()
{
$constraint = new Image([
'minRatio' => 4 / 3,
]);

$this->validator->validate($this->image4By3, $constraint);

$this->assertNoViolation();
}

public function testMaxRatioUsesInputMoreDecimals()
{
$constraint = new Image([
'maxRatio' => 16 / 9,
]);

$this->validator->validate($this->image16By9, $constraint);

$this->assertNoViolation();
}

public function testInvalidMinRatio()
{
$this->expectException(ConstraintDefinitionException::class);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.