Skip to content

Commit 20e6cc9

Browse files
author
symfonyaml
committed
Drop the iterator_to_array() part and tests associated
1 parent 88e1403 commit 20e6cc9

File tree

2 files changed

+2
-26
lines changed

2 files changed

+2
-26
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ public function validate($value, Constraint $constraint)
5656
}
5757
$choices = $choices();
5858
if (!is_array($choices)) {
59-
if (is_iterable($choices)) {
60-
/** @psalm-suppress InvalidArgument */
61-
$choices = iterator_to_array($choices);
62-
} else {
63-
throw new ConstraintDefinitionException(sprintf('The Choice constraint callback "%s" expects to return an iterable, got "%s".', trim($this->formatValue($constraint->callback), '"'), get_debug_type($choices)));
64-
}
59+
throw new ConstraintDefinitionException(sprintf('The Choice constraint callback "%s" is expected to return an array, but returned "%s".', trim($this->formatValue($constraint->callback), '"'), get_debug_type($choices)));
6560
}
6661
} else {
6762
$choices = $constraint->choices;

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

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ public function objectMethodCallback()
3939
return ['foo', 'bar'];
4040
}
4141

42-
public static function staticCallbackTraversable()
43-
{
44-
yield 1;
45-
yield 2;
46-
yield 3;
47-
}
48-
4942
public static function staticCallbackInvalid()
5043
{
5144
return null;
@@ -149,7 +142,7 @@ public function testValidChoiceCallbackContextMethod()
149142
public function testInvalidChoiceCallbackContextMethod()
150143
{
151144
$this->expectException(ConstraintDefinitionException::class);
152-
$this->expectExceptionMessage('The Choice constraint callback "staticCallbackInvalid" expects to return an iterable, got "null".');
145+
$this->expectExceptionMessage('The Choice constraint callback "staticCallbackInvalid" is expected to return an array, but returned "null".');
153146

154147
// search $this for "staticCallbackInvalid"
155148
$this->setObject($this);
@@ -159,18 +152,6 @@ public function testInvalidChoiceCallbackContextMethod()
159152
$this->validator->validate('bar', $constraint);
160153
}
161154

162-
public function testValidChoiceCallbackContextMethodTraversable()
163-
{
164-
// search $this for "staticCallbackTraversable"
165-
$this->setObject($this);
166-
167-
$constraint = new Choice(['callback' => 'staticCallbackTraversable']);
168-
169-
$this->validator->validate(2, $constraint);
170-
171-
$this->assertNoViolation();
172-
}
173-
174155
public function testValidChoiceCallbackContextObjectMethod()
175156
{
176157
// search $this for "objectMethodCallback"

0 commit comments

Comments
 (0)