From e8f505f7e8dee320849933b81c60598ae3e2f7b9 Mon Sep 17 00:00:00 2001 From: SonyPradana Date: Thu, 30 May 2024 21:15:51 +0700 Subject: [PATCH] feat: added push array config --- src/System/Integrate/ConfigRepository.php | 10 ++++++++++ tests/Integrate/ConfigRepositoryTest.php | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/System/Integrate/ConfigRepository.php b/src/System/Integrate/ConfigRepository.php index 8479c59c..7ca485cb 100644 --- a/src/System/Integrate/ConfigRepository.php +++ b/src/System/Integrate/ConfigRepository.php @@ -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. * diff --git a/tests/Integrate/ConfigRepositoryTest.php b/tests/Integrate/ConfigRepositoryTest.php index 9d1fab98..34a0abe7 100644 --- a/tests/Integrate/ConfigRepositoryTest.php +++ b/tests/Integrate/ConfigRepositoryTest.php @@ -12,6 +12,7 @@ public function itCanPerformRepository() 'envi' => 'test', 'num' => 1, 'allow' => true, + 'array' => ['savanna', 'php'], ]; $config = new ConfigRepository($env); @@ -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 */