diff --git a/src/Entity.php b/src/Entity.php index bd1a570..0266236 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -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; } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 716b229..e4c101d 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -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'], diff --git a/tests/EntityTest.php b/tests/EntityTest.php index 31e34f1..113293f 100644 --- a/tests/EntityTest.php +++ b/tests/EntityTest.php @@ -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([ @@ -82,6 +93,10 @@ protected function loadSampleEntity() 'name' => 'Jane', 'email' => 'jane@example.com', ] + ], + 'aliases' => [ + 'Mr Jack Doe', + 'Mr J Doe' ] ]); }