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

Commit 7bfb8c1

Browse filesBrowse files
vudaltsovfabpot
authored andcommitted
[Validator] Fix annotation default for @count and @Length
1 parent c79e52a commit 7bfb8c1
Copy full SHA for 7bfb8c1

File tree

4 files changed

+25
-1
lines changed
Filter options

4 files changed

+25
-1
lines changed

‎src/Symfony/Component/Validator/Constraints/Count.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Count.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public function __construct($options = null)
4343
'min' => $options,
4444
'max' => $options,
4545
];
46+
} elseif (\is_array($options) && isset($options['value']) && !isset($options['min']) && !isset($options['max'])) {
47+
$options['min'] = $options['max'] = $options['value'];
48+
unset($options['value']);
4649
}
4750

4851
parent::__construct($options);

‎src/Symfony/Component/Validator/Constraints/Length.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Constraints/Length.php
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ public function __construct($options = null)
4747
'min' => $options,
4848
'max' => $options,
4949
];
50+
} elseif (\is_array($options) && isset($options['value']) && !isset($options['min']) && !isset($options['max'])) {
51+
$options['min'] = $options['max'] = $options['value'];
52+
unset($options['value']);
5053
}
5154

5255
parent::__construct($options);

‎src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/CountValidatorTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,13 @@ public function testDefaultOption()
195195
$this->assertEquals(5, $constraint->min);
196196
$this->assertEquals(5, $constraint->max);
197197
}
198+
199+
public function testConstraintAnnotationDefaultOption()
200+
{
201+
$constraint = new Count(['value' => 5, 'exactMessage' => 'message']);
202+
203+
$this->assertEquals(5, $constraint->min);
204+
$this->assertEquals(5, $constraint->max);
205+
$this->assertEquals('message', $constraint->exactMessage);
206+
}
198207
}

‎src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Tests/Constraints/LengthValidatorTest.php
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,11 +237,20 @@ public function testOneCharset($value, $charset, $isValid)
237237
}
238238
}
239239

240-
public function testConstraintGetDefaultOption()
240+
public function testConstraintDefaultOption()
241241
{
242242
$constraint = new Length(5);
243243

244244
$this->assertEquals(5, $constraint->min);
245245
$this->assertEquals(5, $constraint->max);
246246
}
247+
248+
public function testConstraintAnnotationDefaultOption()
249+
{
250+
$constraint = new Length(['value' => 5, 'exactMessage' => 'message']);
251+
252+
$this->assertEquals(5, $constraint->min);
253+
$this->assertEquals(5, $constraint->max);
254+
$this->assertEquals('message', $constraint->exactMessage);
255+
}
247256
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.