Skip to content

Commit

Permalink
Merge pull request #44 from peter-gribanov/empty_configuration
Browse files Browse the repository at this point in the history
Allow use empty configuration
  • Loading branch information
peter-gribanov committed Feb 7, 2020
2 parents 506e916 + 15b103e commit 1c74339
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function getConfigTreeBuilder(): TreeBuilder
$root_node
->beforeNormalization()
->ifTrue(static function ($v): bool {
return is_array($v) && !array_key_exists('databases', $v) && !array_key_exists('database', $v);
return $v && is_array($v) && !array_key_exists('databases', $v) && !array_key_exists('database', $v);
})
->then(static function (array $v): array {
// key that should not be rewritten to the database config
Expand All @@ -95,6 +95,7 @@ public function getConfigTreeBuilder(): TreeBuilder
is_array($v) &&
array_key_exists('default_database', $v) &&
array_key_exists('databases', $v) &&
$v['databases'] &&
!array_key_exists($v['default_database'], $v['databases']);
})
->then(static function (array $v): array {
Expand Down
26 changes: 19 additions & 7 deletions tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ public function getBadConfigs(): array
{
$return = [];
foreach (['/tmp/var/cache', null] as $cache_dir) {
$return[] = [$cache_dir, []];
$return[] = [$cache_dir, [
'gpslab_geoip' => null,
]];
$return[] = [$cache_dir, [
'gpslab_geoip' => [],
]];
$return[] = [$cache_dir, [
'gpslab_geoip' => [
'databases' => null,
Expand Down Expand Up @@ -139,6 +132,25 @@ public function getConfigs(): array
foreach (['/tmp/var/cache', null] as $cache_dir) {
$real_cache_dir = $cache_dir ?: sys_get_temp_dir();

$return[] = [$cache_dir, [], [
'locales' => ['en'],
'default_database' => 'default',
'databases' => [],
]];
$return[] = [$cache_dir, [
'gpslab_geoip' => null,
], [
'locales' => ['en'],
'default_database' => 'default',
'databases' => [],
]];
$return[] = [$cache_dir, [
'gpslab_geoip' => [],
], [
'locales' => ['en'],
'default_database' => 'default',
'databases' => [],
]];
$return[] = [$cache_dir, [
'gpslab_geoip' => [
'license' => 'LICENSE',
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/GpsLabGeoIP2ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getCacheDirs(): array
/**
* @dataProvider getCacheDirs
*
* @param mixed $cache_dir
* @param string|bool|null $cache_dir
*/
public function testLoad($cache_dir): void
{
Expand Down

0 comments on commit 1c74339

Please sign in to comment.