Skip to content

Commit

Permalink
Merge pull request #15 from bluemorbo/fix-entities-with-scalar-arrays
Browse files Browse the repository at this point in the history
Fix handling of scalar arrays
  • Loading branch information
rbibby authored Mar 7, 2023
2 parents c20584b + 5a06669 commit dfe016c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ private function findSubEntities($props)

if (is_array($value)) {
$newProps[$name] = array_map(function ($item) {
return new Entity($item);
if (is_object($item) || is_array($item)) {
return new Entity($item);
}

return $item;
}, $value);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public function can_send_query_params_as_array_for_delete_requests()
$this->assertEquals('id:in=1,2,3', urldecode($uri->getQuery()));
}

protected function writeFunctionProvider()
public function writeFunctionProvider()
{
return [
['create'],
Expand Down
15 changes: 15 additions & 0 deletions tests/EntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ public function can_serialize_nested_arrays()
$this->assertEquals('Jane', $this->entity->contacts[1]->name);
}

/**
* @test
*/
public function does_not_serialize_nested_scalar_values()
{
$this->loadSampleEntity();

$this->assertSame("Mr Jack Doe", $this->entity->aliases[0]);
$this->assertSame("Mr J Doe", $this->entity->aliases[1]);
}

protected function loadSampleEntity()
{
$this->entity = new Entity([
Expand All @@ -82,6 +93,10 @@ protected function loadSampleEntity()
'name' => 'Jane',
'email' => '[email protected]',
]
],
'aliases' => [
'Mr Jack Doe',
'Mr J Doe'
]
]);
}
Expand Down

0 comments on commit dfe016c

Please sign in to comment.