From bc0cabb7893238726c72e6643e6b8fa095ef4bda Mon Sep 17 00:00:00 2001 From: Fabdouarrahmane Date: Wed, 25 Sep 2024 17:46:27 +0200 Subject: [PATCH] [Validator][CidrValidator] Fix error message for `OutOfRangeNetmask` validation --- .../Component/Validator/Constraints/CidrValidator.php | 2 +- .../Validator/Tests/Constraints/CidrValidatorTest.php | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/CidrValidator.php b/src/Symfony/Component/Validator/Constraints/CidrValidator.php index 1c6f4c0bc7597..f9dc5c2337a59 100644 --- a/src/Symfony/Component/Validator/Constraints/CidrValidator.php +++ b/src/Symfony/Component/Validator/Constraints/CidrValidator.php @@ -81,7 +81,7 @@ public function validate($value, Constraint $constraint): void $this->context ->buildViolation($constraint->netmaskRangeViolationMessage) ->setParameter('{{ min }}', $constraint->netmaskMin) - ->setParameter('{{ max }}', $constraint->netmaskMax) + ->setParameter('{{ max }}', $netmaskMax) ->setCode(Cidr::OUT_OF_RANGE_ERROR) ->addViolation(); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/CidrValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/CidrValidatorTest.php index 5ac5310941eb7..04d0b89995469 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/CidrValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/CidrValidatorTest.php @@ -106,7 +106,7 @@ public function testInvalidIpAddressAndNetmask(string|\Stringable $cidr) /** * @dataProvider getOutOfRangeNetmask */ - public function testOutOfRangeNetmask(string $cidr, ?string $version = null, ?int $min = null, ?int $max = null) + public function testOutOfRangeNetmask(string $cidr, int $maxExpected, ?string $version = null, ?int $min = null, ?int $max = null) { $cidrConstraint = new Cidr([ 'version' => $version, @@ -118,7 +118,7 @@ public function testOutOfRangeNetmask(string $cidr, ?string $version = null, ?in $this ->buildViolation('The value of the netmask should be between {{ min }} and {{ max }}.') ->setParameter('{{ min }}', $cidrConstraint->netmaskMin) - ->setParameter('{{ max }}', $cidrConstraint->netmaskMax) + ->setParameter('{{ max }}', $maxExpected) ->setCode(Cidr::OUT_OF_RANGE_ERROR) ->assertRaised(); } @@ -240,9 +240,9 @@ public static function getWithInvalidMasksAndIps(): array public static function getOutOfRangeNetmask(): array { return [ - ['10.0.0.0/24', Ip::V4, 10, 20], - ['10.0.0.0/128'], - ['2001:0DB8:85A3:0000:0000:8A2E:0370:7334/24', Ip::V6, 10, 20], + ['10.0.0.0/24', 20, Ip::V4, 10, 20], + ['10.0.0.0/128', 32], + ['2001:0DB8:85A3:0000:0000:8A2E:0370:7334/24', 20, Ip::V6, 10, 20], ]; }