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 24, 2020
1 parent ca1dffe commit 75e5093
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Enforce a timeout for connecting to the server and for the requests instead of waiting indefinitely (#979)
- Add `RequestFetcherInterface` to allow customizing the request data attached to the logged event (#984)
- Log internal debug and error messages to a PSR-3 compatible logger (#989)
- Make `AbstractSerializer` to accept `Traversable` values using `is_iterable` instead of `is_array` (#991)

## 2.3.2 (2020-03-06)

Expand Down
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 75e5093

Please sign in to comment.