Skip to content

Commit 2e391d3

Browse files
author
symfonyaml
committed
Fix tests + iterator_to_array() must implement interface Traversable
1 parent 995f5e3 commit 2e391d3

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public function validate($value, Constraint $constraint)
5252
throw new ConstraintDefinitionException('The Choice constraint expects a valid callback.');
5353
}
5454
$choices = $choices();
55-
if (is_iterable($choices)) {
56-
$choices = iterator_to_array($choices, true);
55+
if ($choices instanceof \Traversable) {
56+
$choices = iterator_to_array($choices);
5757
}
5858
if (!\is_array($choices)) {
5959
throw new ConstraintDefinitionException(\sprintf('The Choice constraint expects the callback to return an iterable value, got "%s".', get_debug_type($choices)));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function testInvalidChoice(Choice $constraint)
200200
public function testInvalidChoiceCallbackContextMethod()
201201
{
202202
$this->expectException(ConstraintDefinitionException::class);
203-
$this->expectExceptionMessage('The Choice constraint expects the callback to return an iterable value, got null.');
203+
$this->expectExceptionMessage('The Choice constraint expects the callback to return an iterable value, got "null".');
204204
// search $this for "staticCallbackInvalid"
205205
$this->setObject($this);
206206

0 commit comments

Comments
 (0)