Skip to content

Commit ad53851

Browse files
Fabdouarrahmanenicolas-grekas
authored andcommitted
[Validator][CidrValidator] Fix error message for OutOfRangeNetmask validation
1 parent e575927 commit ad53851

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

Constraints/CidrValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function validate($value, Constraint $constraint): void
8181
$this->context
8282
->buildViolation($constraint->netmaskRangeViolationMessage)
8383
->setParameter('{{ min }}', $constraint->netmaskMin)
84-
->setParameter('{{ max }}', $constraint->netmaskMax)
84+
->setParameter('{{ max }}', $netmaskMax)
8585
->setCode(Cidr::OUT_OF_RANGE_ERROR)
8686
->addViolation();
8787
}

Tests/Constraints/CidrValidatorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function testInvalidIpAddressAndNetmask(string|\Stringable $cidr)
106106
/**
107107
* @dataProvider getOutOfRangeNetmask
108108
*/
109-
public function testOutOfRangeNetmask(string $cidr, ?string $version = null, ?int $min = null, ?int $max = null)
109+
public function testOutOfRangeNetmask(string $cidr, int $maxExpected, ?string $version = null, ?int $min = null, ?int $max = null)
110110
{
111111
$cidrConstraint = new Cidr([
112112
'version' => $version,
@@ -118,7 +118,7 @@ public function testOutOfRangeNetmask(string $cidr, ?string $version = null, ?in
118118
$this
119119
->buildViolation('The value of the netmask should be between {{ min }} and {{ max }}.')
120120
->setParameter('{{ min }}', $cidrConstraint->netmaskMin)
121-
->setParameter('{{ max }}', $cidrConstraint->netmaskMax)
121+
->setParameter('{{ max }}', $maxExpected)
122122
->setCode(Cidr::OUT_OF_RANGE_ERROR)
123123
->assertRaised();
124124
}
@@ -240,9 +240,9 @@ public static function getWithInvalidMasksAndIps(): array
240240
public static function getOutOfRangeNetmask(): array
241241
{
242242
return [
243-
['10.0.0.0/24', Ip::V4, 10, 20],
244-
['10.0.0.0/128'],
245-
['2001:0DB8:85A3:0000:0000:8A2E:0370:7334/24', Ip::V6, 10, 20],
243+
['10.0.0.0/24', 20, Ip::V4, 10, 20],
244+
['10.0.0.0/128', 32],
245+
['2001:0DB8:85A3:0000:0000:8A2E:0370:7334/24', 20, Ip::V6, 10, 20],
246246
];
247247
}
248248

0 commit comments

Comments
 (0)