From f8897100df665edd09e78e10b51c579ffeb07f8b Mon Sep 17 00:00:00 2001 From: exaby73 Date: Wed, 30 Oct 2024 16:56:50 +0530 Subject: [PATCH 1/2] feat: Add aliases for each driver and its session in Neo4jExtension.php --- src/DependencyInjection/Neo4jExtension.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/DependencyInjection/Neo4jExtension.php b/src/DependencyInjection/Neo4jExtension.php index d366309..d60343b 100644 --- a/src/DependencyInjection/Neo4jExtension.php +++ b/src/DependencyInjection/Neo4jExtension.php @@ -4,6 +4,8 @@ namespace Neo4j\Neo4jBundle\DependencyInjection; +use Laudis\Neo4j\Contracts\DriverInterface; +use Laudis\Neo4j\Contracts\SessionInterface; use Neo4j\Neo4jBundle\Collector\Neo4jDataCollector; use Neo4j\Neo4jBundle\EventHandler; use Neo4j\Neo4jBundle\EventListener\Neo4jProfileListener; @@ -58,6 +60,24 @@ public function load(array $configs, ContainerBuilder $container): ContainerBuil $container->getDefinition('neo4j.driver') ->setArgument(0, $defaultAlias); + foreach ($mergedConfig['drivers'] as $driverConfig) { + $container + ->setDefinition( + 'neo4j.driver.'.$driverConfig['alias'], + (new Definition(DriverInterface::class)) + ->setFactory([new Reference('neo4j.client'), 'getDriver']) + ->setArgument(0, $driverConfig['alias']) + ); + + $container + ->setDefinition( + 'neo4j.session.'.$driverConfig['alias'], + (new Definition(SessionInterface::class)) + ->setFactory([new Reference('neo4j.driver.'.$driverConfig['alias']), 'createSession']) + ->setShared(false) + ); + } + $enabledProfiles = []; foreach ($mergedConfig['drivers'] as $driver) { if (true === $driver['profiling'] || (null === $driver['profiling'] && $container->getParameter( From 1ec5a1c2317a2e5bab2f36a8d67f87fe17c42f92 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Wed, 6 Nov 2024 14:31:58 +0530 Subject: [PATCH 2/2] test: Add tests for new aliases --- src/DependencyInjection/Neo4jExtension.php | 6 ++++-- tests/App/Controller/TestController.php | 4 +--- tests/Functional/IntegrationTest.php | 12 ++++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/DependencyInjection/Neo4jExtension.php b/src/DependencyInjection/Neo4jExtension.php index d60343b..339bf49 100644 --- a/src/DependencyInjection/Neo4jExtension.php +++ b/src/DependencyInjection/Neo4jExtension.php @@ -67,7 +67,8 @@ public function load(array $configs, ContainerBuilder $container): ContainerBuil (new Definition(DriverInterface::class)) ->setFactory([new Reference('neo4j.client'), 'getDriver']) ->setArgument(0, $driverConfig['alias']) - ); + ) + ->setPublic(true); $container ->setDefinition( @@ -75,7 +76,8 @@ public function load(array $configs, ContainerBuilder $container): ContainerBuil (new Definition(SessionInterface::class)) ->setFactory([new Reference('neo4j.driver.'.$driverConfig['alias']), 'createSession']) ->setShared(false) - ); + ) + ->setPublic(true); } $enabledProfiles = []; diff --git a/tests/App/Controller/TestController.php b/tests/App/Controller/TestController.php index 98969b0..63397e5 100644 --- a/tests/App/Controller/TestController.php +++ b/tests/App/Controller/TestController.php @@ -5,8 +5,6 @@ use Laudis\Neo4j\Contracts\ClientInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Profiler\Profiler; -use Symfony\Component\Stopwatch\Stopwatch; class TestController extends AbstractController { @@ -15,7 +13,7 @@ public function __construct( ) { } - public function __invoke(Profiler $profiler, Stopwatch $stopwatch): Response + public function __invoke(): Response { // Successful statement $this->client->run('MATCH (n {foo: $bar}) RETURN n', ['bar' => 'baz']); diff --git a/tests/Functional/IntegrationTest.php b/tests/Functional/IntegrationTest.php index ece543a..8020681 100644 --- a/tests/Functional/IntegrationTest.php +++ b/tests/Functional/IntegrationTest.php @@ -196,6 +196,18 @@ public function testDefaultTransactionConfig(): void $this->assertSame($transactionConfig->getTimeout(), 40.0); } + public function testDriverAndSessionTags(): void + { + static::bootKernel(); + $container = static::getContainer(); + + $this->assertTrue($container->has('neo4j.driver.neo4j-simple')); + $this->assertTrue($container->has('neo4j.driver.neo4j-test')); + + $this->assertTrue($container->has('neo4j.session.neo4j-simple')); + $this->assertTrue($container->has('neo4j.session.neo4j-test')); + } + public function testPriority(): void { static::bootKernel();