13
13
14
14
namespace Laudis \Neo4j \Tests \Integration ;
15
15
16
+ use Exception ;
16
17
use InvalidArgumentException ;
17
18
use Laudis \Neo4j \Authentication \Authenticate ;
18
19
use Laudis \Neo4j \Basic \Driver ;
19
20
use Laudis \Neo4j \Bolt \BoltDriver ;
20
21
use Laudis \Neo4j \Bolt \ConnectionPool ;
21
22
use Laudis \Neo4j \ClientBuilder ;
23
+ use Laudis \Neo4j \Common \DriverSetupManager ;
22
24
use Laudis \Neo4j \Contracts \DriverInterface ;
23
25
use Laudis \Neo4j \Contracts \TransactionInterface ;
26
+ use Laudis \Neo4j \Databags \DriverConfiguration ;
27
+ use Laudis \Neo4j \Databags \DriverSetup ;
24
28
use Laudis \Neo4j \Databags \SessionConfiguration ;
25
29
use Laudis \Neo4j \Databags \Statement ;
30
+ use Laudis \Neo4j \Databags \TransactionConfiguration ;
26
31
use Laudis \Neo4j \Exception \Neo4jException ;
32
+ use Laudis \Neo4j \Formatter \SummarizedResultFormatter ;
27
33
use Laudis \Neo4j \Tests \EnvironmentAwareIntegrationTest ;
34
+ use Psr \Log \LoggerInterface ;
35
+ use Psr \Log \LogLevel ;
28
36
use ReflectionClass ;
37
+ use RuntimeException ;
29
38
30
39
final class ClientIntegrationTest extends EnvironmentAwareIntegrationTest
31
40
{
41
+ public function setUp (): void
42
+ {
43
+ parent ::setUp ();
44
+ $ this ->driver ->closeConnections ();
45
+ }
46
+
47
+ public function testDriverAuthFailureVerifyConnectivity (): void
48
+ {
49
+ if (str_starts_with ($ this ->uri ->getScheme (), 'http ' )) {
50
+ $ this ->markTestSkipped ('HTTP does not support auth failure connectivity passing ' );
51
+ }
52
+
53
+ $ uri = $ this ->uri ->withUserInfo ('neo4j ' , 'absolutelyonehundredpercentawrongpassword ' );
54
+
55
+ $ conf = DriverConfiguration::default ()->withLogger (LogLevel::DEBUG , $ this ->createMock (LoggerInterface::class));
56
+ $ logger = $ conf ->getLogger ();
57
+ if ($ logger === null ) {
58
+ throw new RuntimeException ('Logger not set ' );
59
+ }
60
+
61
+ $ driver = Driver::create ($ uri , $ conf );
62
+
63
+ $ this ->expectException (Neo4jException::class);
64
+ $ this ->expectExceptionMessage (
65
+ 'Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure." '
66
+ );
67
+
68
+ $ driver ->verifyConnectivity ();
69
+ }
70
+
71
+ public function testClientAuthFailureVerifyConnectivity (): void
72
+ {
73
+ if (str_starts_with ($ this ->uri ->getScheme (), 'http ' )) {
74
+ $ this ->markTestSkipped ('HTTP does not support auth failure connectivity passing ' );
75
+ }
76
+
77
+ $ uri = $ this ->uri ->withUserInfo ('neo4j ' , 'absolutelyonehundredpercentawrongpassword ' );
78
+
79
+ /** @noinspection PhpUnhandledExceptionInspection */
80
+ $ conf = DriverConfiguration::default ()->withLogger (LogLevel::DEBUG , $ this ->createMock (LoggerInterface::class));
81
+ $ logger = $ conf ->getLogger ();
82
+ if ($ logger === null ) {
83
+ throw new RuntimeException ('Logger not set ' );
84
+ }
85
+
86
+ $ client = (new ClientBuilder (
87
+ SessionConfiguration::create (),
88
+ TransactionConfiguration::create (),
89
+ (new DriverSetupManager (
90
+ SummarizedResultFormatter::create (),
91
+ $ conf ,
92
+ ))->withSetup (
93
+ new DriverSetup ($ uri , Authenticate::fromUrl ($ uri , $ logger ))
94
+ )
95
+ ))->build ();
96
+
97
+ $ this ->expectException (Neo4jException::class);
98
+ $ this ->expectExceptionMessage (
99
+ 'Neo4j errors detected. First one with code "Neo.ClientError.Security.Unauthorized" and message "The client is unauthorized due to authentication failure." '
100
+ );
101
+
102
+ $ client ->getDriver (null );
103
+ }
104
+
32
105
public function testDifferentAuth (): void
33
106
{
34
107
$ auth = Authenticate::fromUrl ($ this ->getUri ());
@@ -53,28 +126,37 @@ public function testAvailabilityFullImplementation(): void
53
126
54
127
public function testTransactionFunction (): void
55
128
{
56
- $ result = $ this ->getSession ()->transaction (static fn (TransactionInterface $ tsx ) => $ tsx ->run ('UNWIND [1] AS x RETURN x ' )->first ()->getAsInt ('x ' ));
129
+ $ result = $ this ->getSession ()->transaction (
130
+ static fn (TransactionInterface $ tsx ) => $ tsx ->run ('UNWIND [1] AS x RETURN x ' )->first ()->getAsInt ('x ' )
131
+ );
57
132
58
133
self ::assertEquals (1 , $ result );
59
134
60
- $ result = $ this ->getSession ()->readTransaction (static fn (TransactionInterface $ tsx ) => $ tsx ->run ('UNWIND [1] AS x RETURN x ' )->first ()->getAsInt ('x ' ));
135
+ $ result = $ this ->getSession ()->readTransaction (
136
+ static fn (TransactionInterface $ tsx ) => $ tsx ->run ('UNWIND [1] AS x RETURN x ' )->first ()->getAsInt ('x ' )
137
+ );
61
138
62
139
self ::assertEquals (1 , $ result );
63
140
64
- $ result = $ this ->getSession ()->writeTransaction (static fn (TransactionInterface $ tsx ) => $ tsx ->run ('UNWIND [1] AS x RETURN x ' )->first ()->getAsInt ('x ' ));
141
+ $ result = $ this ->getSession ()->writeTransaction (
142
+ static fn (TransactionInterface $ tsx ) => $ tsx ->run ('UNWIND [1] AS x RETURN x ' )->first ()->getAsInt ('x ' )
143
+ );
65
144
66
145
self ::assertEquals (1 , $ result );
67
146
}
68
147
69
148
public function testValidRun (): void
70
149
{
71
- $ response = $ this ->getSession ()->transaction (static fn (TransactionInterface $ tsx ) => $ tsx ->run (<<<'CYPHER'
150
+ $ response = $ this ->getSession ()->transaction (static fn (TransactionInterface $ tsx ) => $ tsx ->run (
151
+ <<<'CYPHER'
72
152
MERGE (x:TestNode {test: $test})
73
153
WITH x
74
154
MERGE (y:OtherTestNode {test: $otherTest})
75
155
WITH x, y, {c: 'd'} AS map, [1, 2, 3] AS list
76
156
RETURN x, y, x.test AS test, map, list
77
- CYPHER, ['test ' => 'a ' , 'otherTest ' => 'b ' ]));
157
+ CYPHER,
158
+ ['test ' => 'a ' , 'otherTest ' => 'b ' ]
159
+ ));
78
160
79
161
self ::assertEquals (1 , $ response ->count ());
80
162
$ map = $ response ->first ();
@@ -89,7 +171,12 @@ public function testValidRun(): void
89
171
public function testInvalidRun (): void
90
172
{
91
173
$ this ->expectException (Neo4jException::class);
92
- $ this ->getSession ()->transaction (static fn (TransactionInterface $ tsx ) => $ tsx ->run ('MERGE (x:Tes0342hdm21.()) ' , ['test ' => 'a ' , 'otherTest ' => 'b ' ]));
174
+ $ this ->getSession ()->transaction (
175
+ static fn (TransactionInterface $ tsx ) => $ tsx ->run (
176
+ 'MERGE (x:Tes0342hdm21.()) ' ,
177
+ ['test ' => 'a ' , 'otherTest ' => 'b ' ]
178
+ )
179
+ );
93
180
}
94
181
95
182
public function testInvalidRunRetry (): void
@@ -108,13 +195,18 @@ public function testInvalidRunRetry(): void
108
195
109
196
public function testValidStatement (): void
110
197
{
111
- $ response = $ this ->getSession ()->transaction (static fn (TransactionInterface $ tsx ) => $ tsx ->runStatement (Statement::create (<<<'CYPHER'
198
+ $ response = $ this ->getSession ()->transaction (static fn (TransactionInterface $ tsx ) => $ tsx ->runStatement (
199
+ Statement::create (
200
+ <<<'CYPHER'
112
201
MERGE (x:TestNode {test: $test})
113
202
WITH x
114
203
MERGE (y:OtherTestNode {test: $otherTest})
115
204
WITH x, y, {c: 'd'} AS map, [1, 2, 3] AS list
116
205
RETURN x, y, x.test AS test, map, list
117
- CYPHER, ['test ' => 'a ' , 'otherTest ' => 'b ' ])));
206
+ CYPHER,
207
+ ['test ' => 'a ' , 'otherTest ' => 'b ' ]
208
+ )
209
+ ));
118
210
119
211
self ::assertEquals (1 , $ response ->count ());
120
212
$ map = $ response ->first ();
@@ -187,9 +279,27 @@ public function testInvalidConnectionCheck(): void
187
279
->withDriver ('http ' , 'http://localboast ' )
188
280
->build ();
189
281
190
- self ::assertFalse ($ client ->verifyConnectivity ('bolt ' ));
191
- self ::assertFalse ($ client ->verifyConnectivity ('neo4j ' ));
192
- self ::assertFalse ($ client ->verifyConnectivity ('http ' ));
282
+ $ exceptionThrownCount = 0 ;
283
+ try {
284
+ $ client ->verifyConnectivity ('bolt ' );
285
+ } catch (Exception $ e ) {
286
+ self ::assertInstanceOf (RuntimeException::class, $ e );
287
+ ++$ exceptionThrownCount ;
288
+ }
289
+ try {
290
+ $ client ->verifyConnectivity ('neo4j ' );
291
+ } catch (Exception $ e ) {
292
+ self ::assertInstanceOf (RuntimeException::class, $ e );
293
+ ++$ exceptionThrownCount ;
294
+ }
295
+ try {
296
+ $ client ->verifyConnectivity ('http ' );
297
+ } catch (Exception $ e ) {
298
+ self ::assertInstanceOf (RuntimeException::class, $ e );
299
+ ++$ exceptionThrownCount ;
300
+ }
301
+
302
+ self ::assertEquals (3 , $ exceptionThrownCount );
193
303
}
194
304
195
305
public function testValidConnectionCheck (): void
0 commit comments