Skip to content

Commit

Permalink
Use is_iterable instead of is_array
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgt9 authored and Alejandro Perez committed Mar 23, 2020
1 parent 4bb4e54 commit 399e98a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Serializer/AbstractSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function serializeRecursively($value, int $_depth = 0)
return $this->serializeCallableWithoutTypeHint($value);
}

if (\is_array($value)) {
if (is_iterable($value)) {
$serializedArray = [];

foreach ($value as $k => $v) {
Expand Down
18 changes: 18 additions & 0 deletions tests/Serializer/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ public function testArraysAreArrays(bool $serializeAllObjects): void
$this->assertSame([1, 2, 3], $result);
}

/**
* @dataProvider serializeAllObjectsDataProvider
*/
public function testTraversablesAreArrays(bool $serializeAllObjects): void
{
$serializer = $this->createSerializer();

if ($serializeAllObjects) {
$serializer->setSerializeAllObjects(true);
}

$content = [1, 2, 3];
$traversable = new \ArrayIterator($content);
$result = $this->invokeSerialization($serializer, $traversable);

$this->assertSame([1, 2, 3], $result);
}

/**
* @dataProvider serializeAllObjectsDataProvider
*/
Expand Down

0 comments on commit 399e98a

Please sign in to comment.