Skip to content

Commit

Permalink
Add logic to GacelaConfig->addAppConfigKeyValues($array)
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusValera committed Jul 15, 2022
1 parent e6dbccd commit 1e4eea3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
10 changes: 10 additions & 0 deletions src/Framework/Bootstrap/GacelaConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ public function addAppConfigKeyValue(string $key, $value): self
return $this;
}

/**
* @param array<string, mixed> $config
*/
public function addAppConfigKeyValues(array $config): self
{
$this->configKeyValues = array_merge($this->configKeyValues, $config);

return $this;
}

/**
* @return array{
* external-services:array<string,class-string|object|callable>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace GacelaTest\Feature\Framework\AddAppConfigKeyValuesInGacelaBootstrap;

use Gacela\Framework\Bootstrap\GacelaConfig;
use Gacela\Framework\ClassResolver\Cache\GacelaCache;
use Gacela\Framework\Gacela;
use GacelaTest\Feature\Framework\AddAppConfigKeyValuesInGacelaBootstrap\Module\Facade;
use PHPUnit\Framework\TestCase;
Expand All @@ -15,12 +14,15 @@ final class FeatureTest extends TestCase
public function setUp(): void
{
Gacela::bootstrap(__DIR__, static function (GacelaConfig $config): void {
$config->addAppConfigKeyValue('first_key', 'individual config key-value');

$config->addAppConfigKeyValues([
GacelaCache::KEY_ENABLED => true,
'some_key' => 'some value',
'another_key' => 'another value',
'override_key' => 'i am going to be overrided',
]);
$config->addAppConfigKeyValue(GacelaCache::KEY_ENABLED, false); // it overrides previous 'GacelaCache::KEY_ENABLED' key

$config->addAppConfigKeyValue('override_key', 'truly override'); // it overrides previous 'override_key' key
});
}

Expand All @@ -29,9 +31,10 @@ public function test_override_factory_from_highest_prio_namespace(): void
$facade = new Facade();

self::assertSame([
GacelaCache::KEY_ENABLED => false,
'first_key' => 'individual config key-value',
'some_key' => 'some value',
'another_key' => 'another value',
'override_key' => 'truly override',
], $facade->getConfigData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
namespace GacelaTest\Feature\Framework\AddAppConfigKeyValuesInGacelaBootstrap\Module;

use Gacela\Framework\AbstractConfig;
use Gacela\Framework\ClassResolver\Cache\GacelaCache;

final class Config extends AbstractConfig
{
public function getData(): array
{
return [
GacelaCache::KEY_ENABLED => $this->get(GacelaCache::KEY_ENABLED),
'first_key' => $this->get('first_key'),
'some_key' => $this->get('some_key'),
'another_key' => $this->get('another_key'),
'override_key' => $this->get('override_key'),
];
}
}

0 comments on commit 1e4eea3

Please sign in to comment.