Skip to content

Commit 6cb860c

Browse files
committed
index value casting fix
1 parent 05d7ce5 commit 6cb860c

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function getValues(array $params): array
6969
$type = array_key_exists(1, $part) ? $part[1] : $part['type'];
7070
$value = Converter::formatValue($type, $params[$part['property']->name]);
7171
if ($value === null && !$part['property']->isNullable) {
72-
$value = Converter::getDefaultValue($format[$field]['type']);
72+
$value = Converter::getDefaultValue($part['property']->type);
7373
}
7474
$values[] = $value;
7575
}

tests/MapperTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,24 @@ public function testMapping()
810810
$this->assertEquals($user, $guest);
811811
}
812812

813+
public function testIndexValueCasting()
814+
{
815+
$mapper = $this->createMapper();
816+
$tester = $mapper->getSchema()
817+
->createSpace('tester', [
818+
'id' => 'integer',
819+
'name' => 'string',
820+
])
821+
->createIndex('id');
822+
823+
$default = $tester->getIndex(0)->getValues([]);
824+
$this->assertSame($default, []);
825+
826+
$default = $tester->getIndex(0)->getValues(['id' => null]);
827+
// type-based default value casting
828+
$this->assertSame($default, [0]);
829+
}
830+
813831
public function testTupleMap()
814832
{
815833
$mapper = $this->createMapper();

0 commit comments

Comments
 (0)