13
13
14
14
namespace Laudis \Neo4j \Tests \Integration ;
15
15
16
+ use Dotenv \Dotenv ;
17
+ use function explode ;
16
18
use InvalidArgumentException ;
17
- use Laudis \ Neo4j \ Bolt \ BoltConfiguration ;
19
+ use function is_string ;
18
20
use Laudis \Neo4j \ClientBuilder ;
21
+ use Laudis \Neo4j \Common \Uri ;
19
22
use Laudis \Neo4j \Contracts \ClientInterface ;
20
23
use Laudis \Neo4j \Contracts \TransactionInterface ;
21
24
use Laudis \Neo4j \Databags \Statement ;
@@ -36,7 +39,17 @@ final class ClientIntegrationTest extends TestCase
36
39
*/
37
40
public function connectionAliases (): iterable
38
41
{
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 ;
40
53
}
41
54
42
55
protected function setUp (): void
@@ -50,12 +63,15 @@ protected function setUp(): void
50
63
*/
51
64
public function createClient (): ClientInterface
52
65
{
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 ();
59
75
}
60
76
61
77
public function testEqualEffect (): void
@@ -65,16 +81,25 @@ public function testEqualEffect(): void
65
81
[
'email ' =>
'[email protected] ' ,
'uuid ' =>
'cc60fd69-a92b-47f3-9674-2f27f3437d66 ' ]
66
82
);
67
83
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 ]);
70
89
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
+ }
73
95
}
74
96
75
- public function testAvailabilityFullImplementation (): void
97
+ /**
98
+ * @dataProvider connectionAliases
99
+ */
100
+ public function testAvailabilityFullImplementation (string $ alias ): void
76
101
{
77
- $ results = $ this ->client ->getDriver (' cluster ' )
102
+ $ results = $ this ->client ->getDriver ($ alias )
78
103
->createSession ()
79
104
->beginTransaction ()
80
105
->run ('UNWIND [1] AS x RETURN x ' )
@@ -84,23 +109,26 @@ public function testAvailabilityFullImplementation(): void
84
109
self ::assertEquals (1 , $ results );
85
110
}
86
111
87
- public function testTransactionFunction (): void
112
+ /**
113
+ * @dataProvider connectionAliases
114
+ */
115
+ public function testTransactionFunction (string $ alias ): void
88
116
{
89
117
$ result = $ this ->client ->transaction (static function (TransactionInterface $ tsx ) {
90
118
return $ tsx ->run ('UNWIND [1] AS x RETURN x ' )->first ()->get ('x ' );
91
- });
119
+ }, $ alias );
92
120
93
121
self ::assertEquals (1 , $ result );
94
122
95
123
$ result = $ this ->client ->readTransaction (static function (TransactionInterface $ tsx ) {
96
124
return $ tsx ->run ('UNWIND [1] AS x RETURN x ' )->first ()->get ('x ' );
97
- });
125
+ }, $ alias );
98
126
99
127
self ::assertEquals (1 , $ result );
100
128
101
129
$ result = $ this ->client ->writeTransaction (static function (TransactionInterface $ tsx ) {
102
130
return $ tsx ->run ('UNWIND [1] AS x RETURN x ' )->first ()->get ('x ' );
103
- });
131
+ }, $ alias );
104
132
105
133
self ::assertEquals (1 , $ result );
106
134
}
@@ -257,4 +285,17 @@ public function testInvalidConnection(): void
257
285
258
286
$ this ->client ->run ('RETURN 1 AS x ' , [], 'ghqkneq;tr ' );
259
287
}
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
+ }
260
301
}
0 commit comments