Skip to content

Commit 3820c8e

Browse files
committed
updated tests to account for multiple drivers and clients
1 parent dc44e47 commit 3820c8e

File tree

6 files changed

+62
-22
lines changed

6 files changed

+62
-22
lines changed

DependencyInjection/Configuration.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ public function getConfigTreeBuilder(): TreeBuilder
6262
->end()
6363
->end()
6464
->end()->end()
65-
->arrayNode('entity_managers')
66-
->requiresAtLeastOneElement()
67-
->useAttributeAsKey('name')
68-
->prototype('array')
69-
->addDefaultsIfNotSet()
70-
->children()
71-
->scalarNode('client')->defaultValue('default')->end()
72-
->scalarNode('cache_dir')->defaultNull()->end()
73-
->end()
74-
->end()->end()
7565
->arrayNode('connections')
7666
->isRequired()
7767
->requiresAtLeastOneElement()

DependencyInjection/Neo4jExtension.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44

55
namespace Neo4j\Neo4jBundle\DependencyInjection;
66

7-
use Laudis\Neo4j\ClientBuilder;
87
use Laudis\Neo4j\Contracts\ClientInterface;
98
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
109
use Symfony\Component\Config\FileLocator;
1110
use Symfony\Component\DependencyInjection\ChildDefinition;
1211
use Symfony\Component\DependencyInjection\ContainerBuilder;
13-
use Symfony\Component\DependencyInjection\Definition;
1412
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
15-
use Symfony\Component\DependencyInjection\Reference;
1613
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1714
use function sprintf;
1815

@@ -34,8 +31,10 @@ public function load(array $configs, ContainerBuilder $container): void
3431

3532
$this->handleClients($config, $container);
3633

37-
$container->setAlias('neo4j.client', 'neo4j.client.default');
38-
$container->setAlias(ClientInterface::class, 'neo4j.client.default');
34+
$container->setAlias('neo4j.client', 'neo4j.client.default')
35+
->setPublic(true);
36+
$container->setAlias(ClientInterface::class, 'neo4j.client.default')
37+
->setPublic(true);
3938

4039
// Configure toolbar
4140
if ($this->isConfigEnabled($container, $config['profiling'])) {
@@ -78,10 +77,10 @@ private function handleClients(array &$config, ContainerBuilder $container): voi
7877
$config['clients']['default'] = ['connections' => ['default']];
7978
}
8079

81-
$serviceIds = [];
8280
foreach ($config['clients'] as $name => $data) {
8381
$connections = [];
84-
$serviceIds[$name] = $serviceId = sprintf('neo4j.client.%s', $name);
82+
$serviceId = sprintf('neo4j.client.%s', $name);
83+
8584
foreach ($data['connections'] as $connectionName) {
8685
if (empty($config['connections'][$connectionName])) {
8786
throw new InvalidConfigurationException(sprintf('Client "%s" is configured to use connection named "%s" but there is no such connection', $name, $connectionName));
@@ -95,7 +94,8 @@ private function handleClients(array &$config, ContainerBuilder $container): voi
9594
$definition = new ChildDefinition('neo4j.client.abstract');
9695

9796
$container->setDefinition($serviceId, $definition)
98-
->setArguments([$connections, $config['connections'], null]);
97+
->setArguments([$connections, $config['connections'], null])
98+
->setPublic(true);
9999
}
100100
}
101101
}

Resources/config/services.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<service id="neo4j.factory.client" class="Neo4j\Neo4jBundle\Factory\ClientFactory" public="false">
88
</service>
99

10-
<service id="neo4j.client.abstract" class="Laudis\Neo4j\Contracts\ClientInterface" abstract="true">
10+
<service id="neo4j.client.abstract" class="Neo4j\Neo4jBundle\SymfonyClient" abstract="true">
1111
<factory service="neo4j.factory.client" method="create" />
1212
</service>
1313
</services>

Tests/Functional/BundleInitializationTest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,61 @@
22

33
namespace Neo4j\Neo4jBundle\Tests\Functional;
44

5+
use InvalidArgumentException;
56
use Laudis\Neo4j\Contracts\ClientInterface;
67

78
/**
89
* @author Tobias Nyholm <[email protected]>
910
*/
1011
class BundleInitializationTest extends BaseTestCase
1112
{
12-
public function testRegisterBundle()
13+
public function testRegisterBundle(): void
1314
{
1415
static::bootKernel();
1516
$container = static::$kernel->getContainer();
1617

1718
$this->assertTrue($container->has('neo4j.client'));
1819
$client = $container->get('neo4j.client');
20+
self::assertInstanceOf(ClientInterface::class, $client);
1921
$this->assertInstanceOf(ClientInterface::class, $client);
22+
23+
$this->assertTrue($container->has(ClientInterface::class));
24+
$client = $container->get(ClientInterface::class);
25+
self::assertInstanceOf(ClientInterface::class, $client);
26+
$this->assertInstanceOf(ClientInterface::class, $client);
27+
}
28+
29+
30+
public function testDefaultDsn(): void
31+
{
32+
static::bootKernel();
33+
$container = static::$kernel->getContainer();
34+
35+
$client = $container->get('neo4j.client');
36+
$this->expectNotToPerformAssertions();
37+
$client->getDriver('default');
38+
}
39+
40+
public function testDsn(): void
41+
{
42+
static::bootKernel();
43+
$container = static::$kernel->getContainer();
44+
45+
$client = $container->get('neo4j.client');
46+
$this->expectNotToPerformAssertions();
47+
$client->getDriver('bolt');
48+
}
49+
50+
public function testSecond(): void
51+
{
52+
static::bootKernel();
53+
$container = static::$kernel->getContainer();
54+
55+
$client = $container->get('neo4j.client.other_client');
56+
self::assertInstanceOf(ClientInterface::class, $client);
57+
$client->getDriver('default');
58+
59+
$this->expectException(InvalidArgumentException::class);
60+
$client->getDriver('bolt');
2061
}
2162
}

Tests/Functional/app/AppKernel.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Neo4j\Neo4jBundle\Tests\Functional\app;
44

55
use Neo4j\Neo4jBundle\Neo4jBundle;
6+
use RuntimeException;
7+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
68
use Symfony\Component\Config\Loader\LoaderInterface;
79
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
810
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -24,7 +26,7 @@ public function __construct($config)
2426
}
2527

2628
if (!file_exists($config)) {
27-
throw new \RuntimeException(sprintf('The config file "%s" does not exist', $config));
29+
throw new RuntimeException(sprintf('The config file "%s" does not exist', $config));
2830
}
2931

3032
$this->config = $config;
@@ -33,7 +35,7 @@ public function __construct($config)
3335
public function registerBundles()
3436
{
3537
return [
36-
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
38+
new FrameworkBundle(),
3739
new Neo4jBundle(),
3840
];
3941
}

Tests/Functional/app/config/default.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ imports:
55
neo4j:
66
connections:
77
default: ~
8+
bolt:
9+
dsn: 'bolt://foo:bar@localhost:7687'
10+
clients:
11+
default:
12+
connections: [ default, bolt ]
13+
other_client:
14+
connections: [ default ]

0 commit comments

Comments
 (0)