Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Cast keys to string on getting data from object
Browse files Browse the repository at this point in the history
  • Loading branch information
michalbundyra committed Dec 24, 2018
1 parent 83568db commit e09022f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ArraySerializableHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function extract(object $object) : array
$filter = $this->getFilter();

foreach ($data as $name => $value) {
$name = (string) $name;

if (! $filter->filter($name)) {
unset($data[$name]);
continue;
Expand Down
14 changes: 14 additions & 0 deletions test/ArraySerializableHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ZendTest\Hydrator;

use ArrayObject;
use PHPUnit\Framework\TestCase;
use TypeError;
use Zend\Hydrator\ArraySerializableHydrator;
Expand Down Expand Up @@ -169,4 +170,17 @@ public function testHydrationWillReplaceNestedArrayData($start, $submit, $expect

$this->assertSame($expected, $final['tags']);
}

public function testExtractArrayObject()
{
$arrayObject = new ArrayObject([
'value1',
'value2',
'value3',
]);

$data = $this->hydrator->extract($arrayObject);

$this->assertSame(['value1', 'value2', 'value3'], $data);
}
}

0 comments on commit e09022f

Please sign in to comment.