From 15ab9787b5a106e15d83aff2e2d6643db73c8750 Mon Sep 17 00:00:00 2001 From: Marc Morera Date: Fri, 22 Apr 2022 11:06:08 +0200 Subject: [PATCH] Fixed item map --- Model/Item.php | 4 +++- Tests/Model/ItemTest.php | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Model/Item.php b/Model/Item.php index 96f9aa9..a85fbff 100644 --- a/Model/Item.php +++ b/Model/Item.php @@ -732,6 +732,8 @@ public function map(callable $callable) $this->highlights = $array['highlights'] ?? []; $this->promoted = isset($array['is_promoted']) && true === $array['is_promoted']; $this->score = $array['score'] ?? null; - $this->coordinate = $array['coordinate'] ?? null; + $this->coordinate = is_array($array['coordinate'] ?? null) + ? Coordinate::createFromArray($array['coordinate']) + : null; } } diff --git a/Tests/Model/ItemTest.php b/Tests/Model/ItemTest.php index 1e65805..7f9e63e 100644 --- a/Tests/Model/ItemTest.php +++ b/Tests/Model/ItemTest.php @@ -524,6 +524,13 @@ public function testMap() $this->assertFalse($item->isPromoted()); $this->assertEquals(10, $item->getScore()); $this->assertNull($item->getCoordinate()); + + $item->map(function (array $map) { + $map['coordinate'] = ['lat' => 1, 'lon' => 2]; + + return $map; + }); + $this->assertInstanceOf(Coordinate::class, $item->getCoordinate()); } /**