Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit dc2538c

Browse files
author
Stefan Gehrig
committed
fixes test setup for neo4j instances running with auth and/or not on default port/host
1 parent 546f105 commit dc2538c

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

tests/Example/ExampleTestCase.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@ abstract class ExampleTestCase extends \PHPUnit_Framework_TestCase
2222

2323
public function setUp()
2424
{
25+
$boltUrl = 'bolt://localhost';
26+
if (isset($_ENV['NEO4J_USER'])) {
27+
$boltUrl = sprintf(
28+
'bolt://%s:%s@%s',
29+
getenv('NEO4J_USER'),
30+
getenv('NEO4J_PASSWORD'),
31+
getenv('NEO4J_HOST')
32+
);
33+
}
34+
2535
$this->client = ClientBuilder::create()
26-
->addConnection('default', 'bolt://localhost')
36+
->addConnection('default', $boltUrl)
2737
->build();
2838
}
2939

tests/Integration/BuildWithEventListenersIntegrationTest.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,28 @@
2222
*/
2323
class BuildWithEventListenersIntegrationTest extends \PHPUnit_Framework_TestCase
2424
{
25+
/**
26+
* @return string
27+
*/
28+
private function createBoltUrl()
29+
{
30+
$boltUrl = 'bolt://localhost';
31+
if (isset($_ENV['NEO4J_USER'])) {
32+
$boltUrl = sprintf(
33+
'bolt://%s:%s@%s',
34+
getenv('NEO4J_USER'),
35+
getenv('NEO4J_PASSWORD'),
36+
getenv('NEO4J_HOST')
37+
);
38+
}
39+
return $boltUrl;
40+
}
41+
2542
public function testListenersAreRegistered()
2643
{
2744
$listener = new EventListener();
2845
$client = ClientBuilder::create()
29-
->addConnection('default', 'bolt://localhost')
46+
->addConnection('default', $this->createBoltUrl())
3047
->registerEventListener(Neo4jClientEvents::NEO4J_PRE_RUN, [$listener, 'onPreRun'])
3148
->registerEventListener(Neo4jClientEvents::NEO4J_POST_RUN, [$listener, 'onPostRun'])
3249
->registerEventListener(Neo4jClientEvents::NEO4J_ON_FAILURE, [$listener, 'onFailure'])
@@ -41,7 +58,7 @@ public function testFailureCanBeDisabled()
4158
{
4259
$listener = new EventListener();
4360
$client = ClientBuilder::create()
44-
->addConnection('default', 'bolt://localhost')
61+
->addConnection('default', $this->createBoltUrl())
4562
->registerEventListener(Neo4jClientEvents::NEO4J_ON_FAILURE, [$listener, 'onFailure'])
4663
->build();
4764

tests/Integration/ClientGetExceptionIntegrationTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ class ClientGetExceptionIntegrationTest extends \PHPUnit_Framework_TestCase
1818
{
1919
public function testExceptionHandling()
2020
{
21+
$boltUrl = 'bolt://localhost';
22+
if (isset($_ENV['NEO4J_USER'])) {
23+
$boltUrl = sprintf(
24+
'bolt://%s:%s@%s',
25+
getenv('NEO4J_USER'),
26+
getenv('NEO4J_PASSWORD'),
27+
getenv('NEO4J_HOST')
28+
);
29+
}
30+
2131
$client = ClientBuilder::create()
22-
->addConnection('default', 'bolt://localhost')
32+
->addConnection('default', $boltUrl)
2333
->build();
2434

2535
$this->setExpectedException(Neo4jException::class);

tests/Integration/ClientSetupIntegrationTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,20 @@ public function testExceptionIsThrownWhenMasterAliasDoesntExist()
115115

116116
public function testSendWriteUseMasterIfAvailable()
117117
{
118+
$httpUri = 'http://localhost:7474';
119+
if (isset($_ENV['NEO4J_USER'])) {
120+
$httpUri = sprintf(
121+
'%s://%s:%s@%s:%s',
122+
getenv('NEO4J_SCHEMA'),
123+
getenv('NEO4J_USER'),
124+
getenv('NEO4J_PASSWORD'),
125+
getenv('NEO4J_HOST'),
126+
getenv('NEO4J_PORT')
127+
);
128+
}
129+
118130
$connectionManager = $this->prophesize(ConnectionManager::class);
119-
$conn = new Connection('default', 'http://localhost:7474', null, 5);
131+
$conn = new Connection('default', $httpUri, null, 5);
120132
$connectionManager->getMasterConnection()->willReturn($conn);
121133
$connectionManager->getMasterConnection()->shouldBeCalled();
122134

tests/Integration/IntegrationTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function setUp()
3737
$boltUrl = 'bolt://localhost';
3838
if (isset($_ENV['NEO4J_USER'])) {
3939
$boltUrl = sprintf(
40-
'bolt://%s:%s@%',
40+
'bolt://%s:%s@%s',
4141
getenv('NEO4J_USER'),
4242
getenv('NEO4J_PASSWORD'),
4343
getenv('NEO4J_HOST')

0 commit comments

Comments
 (0)