8
8
use GuzzleHttp \HandlerStack ;
9
9
use GuzzleHttp \Psr7 \Response ;
10
10
use Neo4j \QueryAPI \Neo4jQueryAPI ;
11
+ use Neo4j \QueryAPI \Objects \Authentication ;
11
12
use Neo4j \QueryAPI \Objects \Bookmarks ;
12
13
use Neo4j \QueryAPI \Objects \ResultCounters ;
13
14
use Neo4j \QueryAPI \Results \ResultRow ;
@@ -24,34 +25,47 @@ protected function setUp(): void
24
25
{
25
26
parent ::setUp ();
26
27
27
- $ this ->address = getenv ('NEO4J_ADDRESS ' );
28
- $ this ->username = getenv ('NEO4J_USERNAME ' );
29
- $ this ->password = getenv ('NEO4J_PASSWORD ' );
28
+ $ this ->address = getenv ('NEO4J_ADDRESS ' ) ;
29
+ $ this ->username = getenv ('NEO4J_USERNAME ' ) ;
30
+ $ this ->password = getenv ('NEO4J_PASSWORD ' ) ;
30
31
}
31
32
32
33
public function testCorrectClientSetup (): void
33
34
{
34
- $ neo4jQueryAPI = Neo4jQueryAPI::login ($ this ->address , $ this ->username , $ this ->password );
35
+ // Verify Authentication object creation
36
+ $ authentication = Authentication::request ($ this ->username , $ this ->password );
37
+ $ expectedAuthHeader = 'Basic ' . base64_encode ("{$ this ->username }: {$ this ->password }" );
38
+ $ this ->assertEquals ($ expectedAuthHeader , $ authentication ->getHeader (), 'Authentication header mismatch. ' );
39
+
40
+ // Use the updated login method
41
+ $ neo4jQueryAPI = Neo4jQueryAPI::login ($ this ->address , $ authentication );
35
42
36
43
$ this ->assertInstanceOf (Neo4jQueryAPI::class, $ neo4jQueryAPI );
37
44
45
+ // Use reflection to access private `client` property
38
46
$ clientReflection = new \ReflectionClass (Neo4jQueryAPI::class);
39
47
$ clientProperty = $ clientReflection ->getProperty ('client ' );
48
+ // Ensure we can access private properties
40
49
$ client = $ clientProperty ->getValue ($ neo4jQueryAPI );
41
50
42
51
$ this ->assertInstanceOf (Client::class, $ client );
43
52
53
+ // Get the client's configuration and check headers
44
54
$ config = $ client ->getConfig ();
45
55
$ this ->assertEquals (rtrim ($ this ->address , '/ ' ), $ config ['base_uri ' ]);
46
- $ this ->assertEquals ('Basic ' . base64_encode ("{$ this ->username }: {$ this ->password }" ), $ config ['headers ' ]['Authorization ' ]);
56
+ $ this ->assertArrayHasKey ('Authorization ' , $ config ['headers ' ], 'Authorization header missing. ' );
57
+ $ this ->assertEquals ($ expectedAuthHeader , $ config ['headers ' ]['Authorization ' ], 'Authorization header value mismatch. ' );
47
58
$ this ->assertEquals ('application/vnd.neo4j.query ' , $ config ['headers ' ]['Content-Type ' ]);
59
+ $ this ->assertEquals ('application/vnd.neo4j.query ' , $ config ['headers ' ]['Accept ' ]);
48
60
}
49
61
62
+
50
63
/**
51
64
* @throws GuzzleException
52
65
*/
53
66
public function testRunSuccess (): void
54
67
{
68
+ // Mock response for a successful query
55
69
$ mock = new MockHandler ([
56
70
new Response (200 , ['X-Foo ' => 'Bar ' ], '{"data": {"fields": ["hello"], "values": [[{"$type": "String", "_value": "world"}]]}} ' ),
57
71
]);
0 commit comments