Skip to content

Commit

Permalink
Add get method with “tests”
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnsn committed Sep 29, 2024
1 parent 4731d57 commit 55af47d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Dictionaries/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public function data(): array
return Arr::except($this->extra, ['label']);
}

public function get($key, $fallback = null)
{
return Arr::get($this->data(), $key, $fallback);
}

public function offsetExists(mixed $offset): bool
{
return true;
Expand Down
2 changes: 2 additions & 0 deletions tests/Dictionaries/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public function it_gets_value_label_and_data()
$this->assertEquals('apple', $item->value());
$this->assertEquals('🍎 Apple', $item->label());
$this->assertEquals(['color' => 'red', 'emoji' => '🍎'], $item->data());
$this->assertEquals('red', $item->get('color'));
$this->assertEquals('red', $item->get('colour', 'red'));
$this->assertEquals([
'key' => 'apple',
'value' => 'apple',
Expand Down

0 comments on commit 55af47d

Please sign in to comment.