Skip to content

Commit

Permalink
Make sure we configure the bundle with a dsn (#47)
Browse files Browse the repository at this point in the history
* Make sure we configure the bundle with a dsn

* Cs

* cs

* Update Neo4jExtension.php
  • Loading branch information
Nyholm authored Mar 6, 2018
1 parent 800a060 commit 9c5d659
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function getConfigTreeBuilder()
->integerNode('port')->end()
->scalarNode('username')->defaultValue('neo4j')->end()
->scalarNode('password')->defaultValue('neo4j')->end()
->scalarNode('dsn')->defaultNull()->end()
->end()
->end()
->end();
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/Neo4jExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ private function handleConnections(array &$config, ContainerBuilder $container):
*/
private function getUrl(array $config): string
{
if (null !== $config['dsn']) {
return $config['dsn'];
}

return sprintf(
'%s://%s:%s@%s:%d',
$config['scheme'],
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ neo4j:
second_connection:
username: foo
password: bar
third_connection:
dsn: 'bolt://foo:bar@localhost:7687'
clients:
default:
connections: [default, second_connection]
connections: [default, second_connection, third_connection]
other_client:
connections: [second_connection]
foobar: ~ # foobar client will have the "default" connection
Expand Down
20 changes: 20 additions & 0 deletions Tests/Unit/DependencyInjection/Neo4jExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,24 @@ protected function getContainerExtensions()
new Neo4jExtension(),
];
}

public function testDefaultDsn()
{
$this->setParameter('kernel.debug', false);
$this->load();
$this->assertContainerBuilderHasServiceDefinitionWithArgument('neo4j.connection.default', 1, 'bolt://neo4j:neo4j@localhost:7474');
}

public function testDsn()
{
$this->setParameter('kernel.debug', false);
$config = ['connections' => [
'default' => [
'dsn' => 'bolt://foo:bar@localhost:7687',
],
]];

$this->load($config);
$this->assertContainerBuilderHasServiceDefinitionWithArgument('neo4j.connection.default', 1, 'bolt://foo:bar@localhost:7687');
}
}

0 comments on commit 9c5d659

Please sign in to comment.