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

Commit

Permalink
Merge pull request #96 from webimpress/hotfix/array-serializable-int-…
Browse files Browse the repository at this point in the history
…keys

Cast keys to string on getting data from object

Conflicts:
	CHANGELOG.md
  • Loading branch information
weierophinney committed Jan 7, 2019
2 parents 0f697c8 + 71ab04d commit 707f5db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ All notable changes to this project will be documented in this file, in reverse
method could not be invoked as documented previously, these changes are
considered bugfixes and not BC breaks.

- [#96](https://github.com/zendframework/zend-hydrator/pull/96) fixes issue with integer keys in `ArraySerializableHydrator`. Keys are now
cast to strings as we have strict type declaration in the library.

## 3.0.0 - 2018-12-10

### Added
Expand Down
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 707f5db

Please sign in to comment.