Skip to content

Commit

Permalink
Merge afe5635 into aeb5276
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed Dec 31, 2020
2 parents aeb5276 + afe5635 commit 624810e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/DependencyInjection/GpsLabGeoIP2Extension.php
Expand Up @@ -16,6 +16,7 @@
use GpsLab\Bundle\GeoIP2Bundle\Command\UpdateDatabaseCommand;
use GpsLab\Bundle\GeoIP2Bundle\Downloader\Downloader;
use GpsLab\Bundle\GeoIP2Bundle\Downloader\MaxMindDownloader;
use GpsLab\Bundle\GeoIP2Bundle\Reader\ReaderFactory;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -90,6 +91,14 @@ public function load(array $configs, ContainerBuilder $container): void
new Reference(Downloader::class),
])
->addTag('console.command');

// configure reader factory service
$container
->setDefinition(ReaderFactory::class, new Definition(ReaderFactory::class))
->setPublic(false)
->setArguments([
$databases,
]);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/DependencyInjection/GpsLabGeoIP2ExtensionTest.php
Expand Up @@ -17,6 +17,7 @@
use GpsLab\Bundle\GeoIP2Bundle\DependencyInjection\GpsLabGeoIP2Extension;
use GpsLab\Bundle\GeoIP2Bundle\Downloader\Downloader;
use GpsLab\Bundle\GeoIP2Bundle\Downloader\MaxMindDownloader;
use GpsLab\Bundle\GeoIP2Bundle\Reader\ReaderFactory;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
Expand Down Expand Up @@ -161,6 +162,16 @@ public function testLoad($cache_dir): void
Downloader::class, // Symfony >= 4.0
strtolower(Downloader::class), // Symfony < 4.0
]);

$this->assertTrue($container->hasDefinition(ReaderFactory::class));
$reader_factory = $container->getDefinition(ReaderFactory::class);
$this->assertFalse($reader_factory->isPublic()); // isPrivate() allowed in Symfony >= 3.4
$this->assertIsArray($reader_factory->getArgument(0));
$this->assertSame(array_keys($databases), array_keys($reader_factory->getArgument(0)));
foreach ($reader_factory->getArgument(0) as $name => $database) {
ksort($database);
$this->assertSame($databases[$name], $database);
}
}

/**
Expand Down

0 comments on commit 624810e

Please sign in to comment.