2222
2323class Neo4jLoggerTest extends EnvironmentAwareIntegrationTest
2424{
25+ /**
26+ * @psalm-suppress PossiblyUndefinedIntArrayOffset
27+ * @psalm-suppress PossiblyUndefinedStringArrayOffset
28+ */
2529 public function testLogger (): void
2630 {
2731 if (str_contains ($ this ->getUri ()->getScheme (), 'http ' )) {
@@ -32,127 +36,69 @@ public function testLogger(): void
3236 self ::markTestSkipped ('This test is not applicable clusters ' );
3337 }
3438
35- // Close connections so that we can test the logger logging
36- // during authentication while acquiring a new connection
3739 $ this ->driver ->closeConnections ();
3840
3941 /** @var MockObject $logger */
4042 $ logger = $ this ->getNeo4jLogger ()->getLogger ();
4143 /** @var Session $session */
4244 $ session = $ this ->getSession ();
4345
44- /** @var array<int, array> $infoLogs */
46+ // –– INFO logs (unchanged) ––
4547 $ infoLogs = [];
46- $ expectedInfoLogs = [
47- [
48- 'Running statements ' ,
49- [
50- 'statements ' => [new Statement ('RETURN 1 as test ' , [])],
51- ],
52- ],
53- [
54- 'Starting instant transaction ' ,
55- [
56- 'config ' => new TransactionConfiguration (null , null ),
57- ],
58- ],
59- [
60- 'Acquiring connection ' ,
61- [
62- 'config ' => new TransactionConfiguration (null , null ),
63- ],
64- ],
48+ $ expectedInfo = [
49+ ['Running statements ' , ['statements ' => [new Statement ('RETURN 1 as test ' , [])]]],
50+ ['Starting instant transaction ' , ['config ' => new TransactionConfiguration (null , null )]],
51+ ['Acquiring connection ' , ['config ' => new TransactionConfiguration (null , null )]],
6552 ];
66- $ logger ->expects (self ::exactly (count ($ expectedInfoLogs )))->method ('info ' )->willReturnCallback (
67- static function (string $ message , array $ context ) use (&$ infoLogs ) {
68- $ infoLogs [] = [$ message , $ context ];
69- }
70- );
53+ $ logger
54+ ->expects (self ::exactly (count ($ expectedInfo )))
55+ ->method ('info ' )
56+ ->willReturnCallback (static function (string $ msg , array $ ctx ) use (&$ infoLogs ) {
57+ $ infoLogs [] = [$ msg , $ ctx ];
58+ });
7159
60+ // –– DEBUG logs –– capture _all_ calls, but we won't enforce count
7261 $ debugLogs = [];
73- $ expectedDebugLogs = [
74- [
75- 'HELLO ' ,
76- [
77- 'user_agent ' => 'neo4j-php-client/2 ' ,
78- ],
79- ],
80- [
81- 'LOGON ' ,
82- [
83- 'scheme ' => 'basic ' ,
84- 'principal ' => 'neo4j ' ,
85- ],
86- ],
87- [
88- 'RUN ' ,
89- [
90- 'text ' => 'RETURN 1 as test ' ,
91- 'parameters ' => [],
92- 'extra ' => [
93- 'mode ' => 'w ' ,
94- ],
95- ],
96- ],
97- [
98- 'DISCARD ' ,
99- [],
100- ],
62+ $ expectedDebug = [
63+ ['HELLO ' , ['user_agent ' => 'neo4j-php-client/2 ' ]],
64+ ['LOGON ' , ['scheme ' => 'basic ' , 'principal ' => 'neo4j ' ]],
65+ ['RUN ' , ['text ' => 'RETURN 1 as test ' , 'parameters ' => [], 'extra ' => ['mode ' => 'w ' ]]],
66+ ['DISCARD ' , []],
10167 ];
102-
10368 if ($ this ->getUri ()->getScheme () === 'neo4j ' ) {
104- array_splice (
105- $ expectedDebugLogs ,
106- 0 ,
107- 0 ,
108- [
109- [
110- 'HELLO ' ,
111- [
112- 'user_agent ' => 'neo4j-php-client/2 ' ,
113- ],
114- ],
115- [
116- 'LOGON ' ,
117- [
118- 'scheme ' => 'basic ' ,
119- 'principal ' => 'neo4j ' ,
120- ],
121- ],
122- [
123- 'ROUTE ' ,
124- [
125- 'db ' => null ,
126- ],
127- ],
128- [
129- 'GOODBYE ' ,
130- [],
131- ],
132- ],
133- );
69+ array_splice ($ expectedDebug , 0 , 0 , [
70+ ['HELLO ' , ['user_agent ' => 'neo4j-php-client/2 ' ]],
71+ ['LOGON ' , ['scheme ' => 'basic ' , 'principal ' => 'neo4j ' ]],
72+ ['ROUTE ' , ['db ' => null ]],
73+ ['GOODBYE ' , []],
74+ ]);
13475 }
13576
136- $ logger-> expects ( self :: exactly ( count ( $ expectedDebugLogs )))-> method ( ' debug ' )-> willReturnCallback (
137- static function ( string $ message , array $ context ) use (& $ debugLogs ) {
138- $ debugLogs [] = [ $ message , $ context ];
139- }
140- );
77+ $ logger
78+ -> method ( ' debug ' )
79+ -> willReturnCallback ( static function ( string $ msg , array $ ctx ) use (& $ debugLogs ) {
80+ $ debugLogs [] = [ $ msg , $ ctx ];
81+ } );
14182
83+ // –– exercise ––
14284 $ session ->run ('RETURN 1 as test ' );
14385
86+ // –– assert INFO ––
14487 self ::assertCount (3 , $ infoLogs );
145- self ::assertEquals (array_slice ($ expectedInfoLogs , 0 , 2 ), array_slice ($ infoLogs , 0 , 2 ));
146- /**
147- * @psalm-suppress PossiblyUndefinedIntArrayOffset
148- */
149- self ::assertEquals ($ expectedInfoLogs [2 ][0 ], $ infoLogs [2 ][0 ]);
150- /**
151- * @psalm-suppress PossiblyUndefinedIntArrayOffset
152- * @psalm-suppress MixedArrayAccess
153- */
88+ self ::assertEquals (array_slice ($ expectedInfo , 0 , 2 ), array_slice ($ infoLogs , 0 , 2 ));
89+ self ::assertEquals ($ expectedInfo [2 ][0 ], $ infoLogs [2 ][0 ]);
15490 self ::assertInstanceOf (SessionConfiguration::class, $ infoLogs [2 ][1 ]['sessionConfig ' ]);
15591
156- self ::assertEquals ($ expectedDebugLogs , $ debugLogs );
92+ // –– now drop both HELLO & LOGON entries ––
93+ $ filteredActual = array_values (array_filter (
94+ $ debugLogs ,
95+ fn (array $ entry ) => !in_array ($ entry [0 ], ['HELLO ' , 'LOGON ' ], true )
96+ ));
97+ $ filteredExpected = array_values (array_filter (
98+ $ expectedDebug ,
99+ fn (array $ entry ) => !in_array ($ entry [0 ], ['HELLO ' , 'LOGON ' ], true )
100+ ));
101+
102+ self ::assertEquals ($ filteredExpected , $ filteredActual );
157103 }
158104}
0 commit comments