Skip to content

Commit 012a42b

Browse files
authored
Merge pull request #142 from apisearch-io/fix/fixed-item-map
Fixed item map
2 parents 2780556 + 15ab978 commit 012a42b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Model/Item.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ public function map(callable $callable)
732732
$this->highlights = $array['highlights'] ?? [];
733733
$this->promoted = isset($array['is_promoted']) && true === $array['is_promoted'];
734734
$this->score = $array['score'] ?? null;
735-
$this->coordinate = $array['coordinate'] ?? null;
735+
$this->coordinate = is_array($array['coordinate'] ?? null)
736+
? Coordinate::createFromArray($array['coordinate'])
737+
: null;
736738
}
737739
}

Tests/Model/ItemTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,13 @@ public function testMap()
524524
$this->assertFalse($item->isPromoted());
525525
$this->assertEquals(10, $item->getScore());
526526
$this->assertNull($item->getCoordinate());
527+
528+
$item->map(function (array $map) {
529+
$map['coordinate'] = ['lat' => 1, 'lon' => 2];
530+
531+
return $map;
532+
});
533+
$this->assertInstanceOf(Coordinate::class, $item->getCoordinate());
527534
}
528535

529536
/**

0 commit comments

Comments
 (0)