Skip to content

Commit dc347d8

Browse files
committed
Merge branch 'rtyshyk-fix-data-iterable' into 7.4
2 parents b6f3aff + 1a73abd commit dc347d8

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Elasticsearch/Client.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,9 @@ public function extractArgument(array &$params, string $arg)
12751275
{
12761276
if (array_key_exists($arg, $params) === true) {
12771277
$value = $params[$arg];
1278-
$value = is_object($value) ? (array) $value : $value;
1278+
$value = (is_object($value) && !is_iterable($value)) ?
1279+
(array) $value :
1280+
$value;
12791281
unset($params[$arg]);
12801282
return $value;
12811283
} else {

tests/Elasticsearch/Tests/ClientTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,16 @@ public function testClientLazy()
478478
$result = $client->info($params);
479479
$this->assertInstanceOf(FutureArray::class, $result);
480480
}
481+
482+
public function testExtractArgumentIterable()
483+
{
484+
$client = Elasticsearch\ClientBuilder::create()->build();
485+
// array iterator can be casted to array back, so make more real with IteratorIterator
486+
$body = new \IteratorIterator(new \ArrayIterator([1, 2, 3]));
487+
$params = ['body' => $body];
488+
$argument = $client->extractArgument($params, 'body');
489+
$this->assertEquals($body, $argument);
490+
$this->assertCount(0, $params);
491+
$this->assertInstanceOf(\IteratorIterator::class, $argument);
492+
}
481493
}

0 commit comments

Comments
 (0)