88use GuzzleHttp \HandlerStack ;
99use GuzzleHttp \Psr7 \Response ;
1010use Neo4j \QueryAPI \Neo4jQueryAPI ;
11+ use Neo4j \QueryAPI \Objects \Authentication ;
1112use Neo4j \QueryAPI \Objects \Bookmarks ;
1213use Neo4j \QueryAPI \Objects \ResultCounters ;
1314use Neo4j \QueryAPI \Results \ResultRow ;
@@ -24,34 +25,47 @@ protected function setUp(): void
2425 {
2526 parent ::setUp ();
2627
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 ' ) ;
3031 }
3132
3233 public function testCorrectClientSetup (): void
3334 {
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 );
3542
3643 $ this ->assertInstanceOf (Neo4jQueryAPI::class, $ neo4jQueryAPI );
3744
45+ // Use reflection to access private `client` property
3846 $ clientReflection = new \ReflectionClass (Neo4jQueryAPI::class);
3947 $ clientProperty = $ clientReflection ->getProperty ('client ' );
48+ // Ensure we can access private properties
4049 $ client = $ clientProperty ->getValue ($ neo4jQueryAPI );
4150
4251 $ this ->assertInstanceOf (Client::class, $ client );
4352
53+ // Get the client's configuration and check headers
4454 $ config = $ client ->getConfig ();
4555 $ 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. ' );
4758 $ this ->assertEquals ('application/vnd.neo4j.query ' , $ config ['headers ' ]['Content-Type ' ]);
59+ $ this ->assertEquals ('application/vnd.neo4j.query ' , $ config ['headers ' ]['Accept ' ]);
4860 }
4961
62+
5063 /**
5164 * @throws GuzzleException
5265 */
5366 public function testRunSuccess (): void
5467 {
68+ // Mock response for a successful query
5569 $ mock = new MockHandler ([
5670 new Response (200 , ['X-Foo ' => 'Bar ' ], '{"data": {"fields": ["hello"], "values": [[{"$type": "String", "_value": "world"}]]}} ' ),
5771 ]);
0 commit comments