Skip to content

Commit 8f7862e

Browse files
committed
make flexible logging test for compatibility between neo4j 4 and 5
1 parent ffbdb6a commit 8f7862e

7 files changed

+64
-133
lines changed

.github/workflows/integration-test-aura.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
concurrency:
1010
group: integration-tests-aura
11-
cancel-in-progress: false
11+
cancel-in-progress: true
1212

1313
jobs:
1414
tests:

.github/workflows/integration-test-cluster-neo4j-4.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ jobs:
2424
2525
- name: Run integration tests
2626
run: |
27-
# install PHP deps and run PHPUnit inside the client container
27+
docker compose -f docker-compose-neo4j-4.yml up -d --build --remove-orphans --wait \
28+
server1 \
29+
server2 \
30+
server3 \
31+
server4
32+
2833
docker compose -f docker-compose-neo4j-4.yml run --rm client \
2934
sh -c "composer install && ./vendor/bin/phpunit -c phpunit.xml.dist --testsuite Integration"
3035

.github/workflows/integration-test-cluster-neo4j-5.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ jobs:
2323
2424
- name: Run integration tests
2525
run: |
26+
docker compose up -d --build --remove-orphans --wait \
27+
server1 \
28+
server2 \
29+
server3 \
30+
server4
31+
2632
# install PHP deps and run PHPUnit inside the client container
2733
docker compose run --rm client \
2834
sh -c "composer install && ./vendor/bin/phpunit -c phpunit.xml.dist --testsuite Integration"

.github/workflows/integration-test-single-server.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
echo "CONNECTION=neo4j://neo4j:testtest@neo4j" >> .env
3232
3333
docker compose -f docker-compose-neo4j-4.yml run --rm --no-deps \
34-
client sh -c "composer install && ./vendor/bin/phpunit -c phpunit.xml.dist --testsuite Integration"
34+
client sh -c "./vendor/bin/phpunit -c phpunit.xml.dist --testsuite Integration"
3535
3636
docker compose -f docker-compose-neo4j-4.yml down --remove-orphans --volumes
3737
@@ -44,10 +44,6 @@ jobs:
4444

4545
steps:
4646
- uses: actions/checkout@v4
47-
- name: Populate .env
48-
run: |
49-
echo "PHP_VERSION=${{ matrix.php }}" > .env
50-
echo "CONNECTION=neo4j://neo4j:testtest@neo4j" >> .env
5147
- name: Run tests Neo4j 5
5248
run: |
5349
echo "PHP_VERSION=${{ matrix.php }}" > .env
@@ -62,6 +58,6 @@ jobs:
6258
echo "CONNECTION=neo4j://neo4j:testtest@neo4j" >> .env
6359
6460
docker compose run --rm --no-deps \
65-
client sh -c "composer install && ./vendor/bin/phpunit -c phpunit.xml.dist --testsuite Integration"
61+
client sh -c "./vendor/bin/phpunit -c phpunit.xml.dist --testsuite Integration"
6662
6763
docker compose down --remove-orphans --volumes

docker-compose-neo4j-4.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,6 @@ services:
3939
- .:/opt/project
4040
env_file:
4141
- .env
42-
depends_on:
43-
neo4j:
44-
condition: service_healthy
45-
server1:
46-
condition: service_healthy
47-
server2:
48-
condition: service_healthy
49-
server3:
50-
condition: service_healthy
51-
server4:
52-
condition: service_healthy
5342
neo4j:
5443
image: neo4j:4.4-enterprise
5544
healthcheck:
@@ -62,8 +51,8 @@ services:
6251
- "7474:7474"
6352
environment:
6453
<<: *common
65-
NEO4J_dbms_connector_http_advertised__address: server1:7474
66-
NEO4J_dbms_connector_bolt_advertised__address: server1:7687
54+
NEO4J_dbms_connector_http_advertised__address: neo4j:7474
55+
NEO4J_dbms_connector_bolt_advertised__address: neo4j:7687
6756
env_file:
6857
- .env
6958
networks:

docker-compose.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,6 @@ services:
5050
- .:/opt/project
5151
env_file:
5252
- .env
53-
depends_on:
54-
neo4j:
55-
condition: service_healthy
56-
server1:
57-
condition: service_healthy
58-
server2:
59-
condition: service_healthy
60-
server3:
61-
condition: service_healthy
62-
server4:
63-
condition: service_healthy
6453
neo4j:
6554
<<: *common
6655
image: neo4j:5.23-community

tests/Integration/Neo4jLoggerTest.php

Lines changed: 47 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
class 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

Comments
 (0)