Skip to content

Commit 3b32cb8

Browse files
committed
added dynamic uris from environment
1 parent b4ef181 commit 3b32cb8

File tree

4 files changed

+63
-19
lines changed

4 files changed

+63
-19
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEO4J_CONNECTIONS=bolt://neo4j:test@neo4j,http://neo4j:test@neo4j,bolt://neo4j:test@core1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ clover.xml
88
cc-test-reporter
99
/run-pipeline.sh
1010
composer.lock
11+
.env

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
"kriswallsmith/buzz": "^1.2",
4949
"vimeo/psalm": "^4.7",
5050
"friendsofphp/php-cs-fixer": "^2.19",
51-
"psalm/plugin-phpunit": "^0.15.1"
51+
"psalm/plugin-phpunit": "^0.15.1",
52+
"vlucas/phpdotenv": "^5.0"
5253
},
5354
"autoload": {
5455
"psr-4": {

tests/Integration/ClientIntegrationTest.php

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@
1313

1414
namespace Laudis\Neo4j\Tests\Integration;
1515

16+
use Dotenv\Dotenv;
17+
use function explode;
1618
use InvalidArgumentException;
17-
use Laudis\Neo4j\Bolt\BoltConfiguration;
19+
use function is_string;
1820
use Laudis\Neo4j\ClientBuilder;
21+
use Laudis\Neo4j\Common\Uri;
1922
use Laudis\Neo4j\Contracts\ClientInterface;
2023
use Laudis\Neo4j\Contracts\TransactionInterface;
2124
use Laudis\Neo4j\Databags\Statement;
@@ -36,7 +39,17 @@ final class ClientIntegrationTest extends TestCase
3639
*/
3740
public function connectionAliases(): iterable
3841
{
39-
return [['bolt'], ['http'], ['cluster']];
42+
Dotenv::createImmutable(__DIR__.'/../../')->safeLoad();
43+
$connections = $this->getConnections();
44+
45+
$tbr = [];
46+
foreach ($connections as $i => $connection) {
47+
$uri = Uri::create($connection);
48+
$tbr[] = [$uri->getScheme().'_'.$i];
49+
}
50+
51+
/** @var non-empty-array<array-key, array{0: string}> */
52+
return $tbr;
4053
}
4154

4255
protected function setUp(): void
@@ -50,12 +63,15 @@ protected function setUp(): void
5063
*/
5164
public function createClient(): ClientInterface
5265
{
53-
return ClientBuilder::create()
54-
->addBoltConnection('bolt', 'bolt://neo4j:test@neo4j')
55-
->addHttpConnection('http', 'http://neo4j:test@neo4j')
56-
->addBoltConnection('cluster', 'bolt://neo4j:test@core1', BoltConfiguration::create()->withAutoRouting(true))
57-
->withFormatter(new BasicFormatter())
58-
->build();
66+
$connections = $this->getConnections();
67+
68+
$builder = ClientBuilder::create();
69+
foreach ($connections as $i => $connection) {
70+
$uri = Uri::create($connection);
71+
$builder = $builder->withDriver($uri->getScheme().'_'.$i, $connection);
72+
}
73+
74+
return $builder->withFormatter(new BasicFormatter())->build();
5975
}
6076

6177
public function testEqualEffect(): void
@@ -65,16 +81,25 @@ public function testEqualEffect(): void
6581
['email' => '[email protected]', 'uuid' => 'cc60fd69-a92b-47f3-9674-2f27f3437d66']
6682
);
6783

68-
$x = $this->client->runStatement($statement, 'bolt');
69-
$y = $this->client->runStatement($statement, 'http');
84+
$prev = null;
85+
foreach ($this->connectionAliases() as $current) {
86+
if ($prev !== null) {
87+
$x = $this->client->runStatement($statement, $prev);
88+
$y = $this->client->runStatement($statement, $current[0]);
7089

71-
self::assertEquals($x, $y);
72-
self::assertEquals($x->toArray(), $y->toArray());
90+
self::assertEquals($x, $y);
91+
self::assertEquals($x->toArray(), $y->toArray());
92+
}
93+
$prev = $current[0];
94+
}
7395
}
7496

75-
public function testAvailabilityFullImplementation(): void
97+
/**
98+
* @dataProvider connectionAliases
99+
*/
100+
public function testAvailabilityFullImplementation(string $alias): void
76101
{
77-
$results = $this->client->getDriver('cluster')
102+
$results = $this->client->getDriver($alias)
78103
->createSession()
79104
->beginTransaction()
80105
->run('UNWIND [1] AS x RETURN x')
@@ -84,23 +109,26 @@ public function testAvailabilityFullImplementation(): void
84109
self::assertEquals(1, $results);
85110
}
86111

87-
public function testTransactionFunction(): void
112+
/**
113+
* @dataProvider connectionAliases
114+
*/
115+
public function testTransactionFunction(string $alias): void
88116
{
89117
$result = $this->client->transaction(static function (TransactionInterface $tsx) {
90118
return $tsx->run('UNWIND [1] AS x RETURN x')->first()->get('x');
91-
});
119+
}, $alias);
92120

93121
self::assertEquals(1, $result);
94122

95123
$result = $this->client->readTransaction(static function (TransactionInterface $tsx) {
96124
return $tsx->run('UNWIND [1] AS x RETURN x')->first()->get('x');
97-
});
125+
}, $alias);
98126

99127
self::assertEquals(1, $result);
100128

101129
$result = $this->client->writeTransaction(static function (TransactionInterface $tsx) {
102130
return $tsx->run('UNWIND [1] AS x RETURN x')->first()->get('x');
103-
});
131+
}, $alias);
104132

105133
self::assertEquals(1, $result);
106134
}
@@ -257,4 +285,17 @@ public function testInvalidConnection(): void
257285

258286
$this->client->run('RETURN 1 AS x', [], 'ghqkneq;tr');
259287
}
288+
289+
/**
290+
* @return list<string>
291+
*/
292+
private function getConnections(): array
293+
{
294+
$connections = $_ENV['NEO4J_CONNECTIONS'] ?? false;
295+
if (!is_string($connections)) {
296+
return [];
297+
}
298+
299+
return explode(',', $connections);
300+
}
260301
}

0 commit comments

Comments
 (0)