From f4e1b1ac9ceed8f15eadc38ee3bf4e014e2c47b6 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Dec 2020 17:56:13 +0300 Subject: [PATCH 1/2] configure reader factory service --- src/DependencyInjection/GpsLabGeoIP2Extension.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/DependencyInjection/GpsLabGeoIP2Extension.php b/src/DependencyInjection/GpsLabGeoIP2Extension.php index f54bca5..d30af74 100644 --- a/src/DependencyInjection/GpsLabGeoIP2Extension.php +++ b/src/DependencyInjection/GpsLabGeoIP2Extension.php @@ -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; @@ -87,6 +88,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, + ]); } /** From afe5635cff310edc3c1392a3fa4e96fd243b3fe1 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Thu, 31 Dec 2020 20:28:33 +0300 Subject: [PATCH 2/2] test configure reader factory service --- .../DependencyInjection/GpsLabGeoIP2ExtensionTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/DependencyInjection/GpsLabGeoIP2ExtensionTest.php b/tests/DependencyInjection/GpsLabGeoIP2ExtensionTest.php index a44571c..d8cae34 100644 --- a/tests/DependencyInjection/GpsLabGeoIP2ExtensionTest.php +++ b/tests/DependencyInjection/GpsLabGeoIP2ExtensionTest.php @@ -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; @@ -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); + } } /**