Skip to content

Commit

Permalink
feat: added push array config
Browse files Browse the repository at this point in the history
  • Loading branch information
SonyPradana committed May 30, 2024
1 parent c749e53 commit e8f505f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/System/Integrate/ConfigRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ public function set(string $key, mixed $value): void
$this->config[$key] = $value;
}

/**
* Push value in an array items.
*/
public function push(string $key, mixed $value): void
{
$array = $this->get($key, []);
$array[] = $value;
$this->set($key, $array);
}

/**
* Convert back to array.
*
Expand Down
4 changes: 4 additions & 0 deletions tests/Integrate/ConfigRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function itCanPerformRepository()
'envi' => 'test',
'num' => 1,
'allow' => true,
'array' => ['savanna', 'php'],
];

$config = new ConfigRepository($env);
Expand All @@ -22,6 +23,9 @@ public function itCanPerformRepository()
$this->assertEquals('local', (fn () => $this->{'config'}['envi'])->call($config));
// has
$this->assertTrue($config->has('num'));
// push
$config->push('array', 'library');
$this->assertEquals(['savanna', 'php', 'library'], (fn () => $this->{'config'}['array'])->call($config));
}

/** @test */
Expand Down

0 comments on commit e8f505f

Please sign in to comment.