Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 1 addition & 1 deletion src/Symfony/Component/Validator/Constraints/Range.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function __construct(
throw new LogicException(sprintf('The "%s" constraint requires the Symfony PropertyAccess component to use the "minPropertyPath" or "maxPropertyPath" option. Try running "composer require symfony/property-access".', static::class));
}

if (null !== $this->min && null !== $this->max && ($minMessage || $maxMessage)) {
if (null !== $this->min && null !== $this->max && ($minMessage || $maxMessage || isset($options['minMessage']) || isset($options['maxMessage']))) {
throw new ConstraintDefinitionException(sprintf('The "%s" constraint can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.', static::class));
}
}
Expand Down
56 changes: 52 additions & 4 deletions src/Symfony/Component/Validator/Tests/Constraints/RangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testThrowsConstraintExceptionIfBothMinLimitAndPropertyPath()

public function testThrowsConstraintExceptionIfBothMinLimitAndPropertyPathNamed()
{
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage('requires only one of the "min" or "minPropertyPath" options to be set, not both.');
new Range(min: 'min', minPropertyPath: 'minPropertyPath');
}
Expand All @@ -47,7 +47,7 @@ public function testThrowsConstraintExceptionIfBothMaxLimitAndPropertyPath()

public function testThrowsConstraintExceptionIfBothMaxLimitAndPropertyPathNamed()
{
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage('requires only one of the "max" or "maxPropertyPath" options to be set, not both.');
new Range(max: 'max', maxPropertyPath: 'maxPropertyPath');
}
Expand All @@ -65,10 +65,58 @@ public function testThrowsNoDefaultOptionConfiguredException()
new Range('value');
}

public function testThrowsConstraintDefinitionExceptionIfBothMinAndMaxAndMinMessageOrMaxMessage()
public function testThrowsConstraintDefinitionExceptionIfBothMinAndMaxAndMinMessageAndMaxMessage()
{
$this->expectException(\Symfony\Component\Validator\Exception\ConstraintDefinitionException::class);
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage('can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.');
new Range(min: 'min', max: 'max', minMessage: 'minMessage', maxMessage: 'maxMessage');
}

public function testThrowsConstraintDefinitionExceptionIfBothMinAndMaxAndMinMessage()
{
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage('can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.');
new Range(min: 'min', max: 'max', minMessage: 'minMessage');
}

public function testThrowsConstraintDefinitionExceptionIfBothMinAndMaxAndMaxMessage()
{
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage('can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.');
new Range(min: 'min', max: 'max', maxMessage: 'maxMessage');
}

public function testThrowsConstraintDefinitionExceptionIfBothMinAndMaxAndMinMessageAndMaxMessageOptions()
{
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage('can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.');
new Range([
'min' => 'min',
'minMessage' => 'minMessage',
'max' => 'max',
'maxMessage' => 'maxMessage',
]);
}

public function testThrowsConstraintDefinitionExceptionIfBothMinAndMaxAndMinMessageOptions()
{
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage('can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.');
new Range([
'min' => 'min',
'minMessage' => 'minMessage',
'max' => 'max',
]);
}

public function testThrowsConstraintDefinitionExceptionIfBothMinAndMaxAndMaxMessageOptions()
{
$this->expectException(ConstraintDefinitionException::class);
$this->expectExceptionMessage('can not use "minMessage" and "maxMessage" when the "min" and "max" options are both set. Use "notInRangeMessage" instead.');
new Range([
'min' => 'min',
'max' => 'max',
'maxMessage' => 'maxMessage',
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1037,30 +1037,6 @@ public static function provideMessageIfMinAndMaxSet(): array
'not_in_range_message',
Range::NOT_IN_RANGE_ERROR,
],
[
['minMessage' => 'min_message'],
0,
$notInRangeMessage,
Range::NOT_IN_RANGE_ERROR,
],
[
['maxMessage' => 'max_message'],
0,
$notInRangeMessage,
Range::NOT_IN_RANGE_ERROR,
],
[
['minMessage' => 'min_message'],
15,
$notInRangeMessage,
Range::NOT_IN_RANGE_ERROR,
],
[
['maxMessage' => 'max_message'],
15,
$notInRangeMessage,
Range::NOT_IN_RANGE_ERROR,
],
];
}

Expand Down