Skip to content

Commit

Permalink
Boolean processing error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Helldar committed Apr 8, 2022
1 parent 9c21c5f commit be15496
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/DataTransferObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ protected function setItems(array $items): void

protected function getValueByKey(array $items, string $key, string $default)
{
return Arr::get($items, $key) ?: Arr::get($items, $default);
if (Arr::exists($items, $key)) {
return Arr::get($items, $key);
}

return Arr::get($items, $default);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Unit/MapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,23 @@ public function testToArray()
'baz' => $this->baz,
], $object->toArray());
}

public function testMissingValues()
{
$object = new Map([
'wa' => [
'sd' => $this->foo,
],

'qwe.rty' => false,
]);

$this->assertIsArray($object->toArray());

$this->assertSame([
'foo' => $this->foo,
'bar' => false,
'baz' => null,
], $object->toArray());
}
}

0 comments on commit be15496

Please sign in to comment.