Skip to content

Commit 602d84f

Browse files
[Validator] Fix constraints on WordCount properties
1 parent e63495e commit 602d84f

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/Symfony/Component/Validator/Constraints/WordCount.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public function __construct(
4848
throw new MissingOptionsException(\sprintf('Either option "min" or "max" must be given for constraint "%s".', __CLASS__), ['min', 'max']);
4949
}
5050

51-
if (null !== $min && $min < 0) {
52-
throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires the min word count to be a positive integer or 0 if set.', __CLASS__));
51+
if (null !== $min && $min <= 0) {
52+
throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires the min word count to be a positive integer if set.', __CLASS__));
5353
}
5454

5555
if (null !== $max && $max <= 0) {

src/Symfony/Component/Validator/Tests/Constraints/WordCountTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,31 @@ public function testOnlyMaxIsSet()
4848
$this->assertNull($wordCount->locale);
4949
}
5050

51-
public function testMinMustBeNatural()
51+
public function testMinIsNegative()
5252
{
5353
$this->expectException(ConstraintDefinitionException::class);
54-
$this->expectExceptionMessage('The "Symfony\Component\Validator\Constraints\WordCount" constraint requires the min word count to be a positive integer or 0 if set.');
54+
$this->expectExceptionMessage('The "Symfony\Component\Validator\Constraints\WordCount" constraint requires the min word count to be a positive integer if set.');
5555

5656
new WordCount(-1);
5757
}
5858

59-
public function testMaxMustBePositive()
59+
public function testMinIsZero()
60+
{
61+
$this->expectException(ConstraintDefinitionException::class);
62+
$this->expectExceptionMessage('The "Symfony\Component\Validator\Constraints\WordCount" constraint requires the min word count to be a positive integer if set.');
63+
64+
new WordCount(0);
65+
}
66+
67+
public function testMaxIsNegative()
68+
{
69+
$this->expectException(ConstraintDefinitionException::class);
70+
$this->expectExceptionMessage('The "Symfony\Component\Validator\Constraints\WordCount" constraint requires the max word count to be a positive integer if set.');
71+
72+
new WordCount(max: -1);
73+
}
74+
75+
public function testMaxIsZero()
6076
{
6177
$this->expectException(ConstraintDefinitionException::class);
6278
$this->expectExceptionMessage('The "Symfony\Component\Validator\Constraints\WordCount" constraint requires the max word count to be a positive integer if set.');

0 commit comments

Comments
 (0)