Skip to content

Commit c09d2c0

Browse files
committed
[Server] Make CollectingLogger test fixture compatible with psr/log v1
The anonymous logger in StreamableHttpTransportTest used the v2/v3 method signature `log($level, \Stringable|string $message, ...)`. Project composer.json allows psr/log ^1.0 || ^2.0 || ^3.0, so on `--prefer-lowest` CI installs v1 which keeps the untyped parameter and fatals on LSP incompatibility. Drop the type hint to keep the fixture working across all three major versions.
1 parent 3a40738 commit c09d2c0

2 files changed

Lines changed: 9 additions & 25 deletions

File tree

tests/Conformance/conformance-baseline.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
server: []
1+
server:
2+
- server-sse-multiple-streams
23

34
client:
45
- elicitation-sep1034-client-defaults

tests/Unit/Server/Transport/StreamableHttpTransportTest.php

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Psr\Http\Message\ServerRequestInterface;
2525
use Psr\Http\Server\MiddlewareInterface;
2626
use Psr\Http\Server\RequestHandlerInterface;
27-
use Psr\Log\AbstractLogger;
27+
use Psr\Log\LoggerInterface;
2828

2929
final class StreamableHttpTransportTest extends TestCase
3030
{
@@ -93,7 +93,10 @@ public function testEmptyMiddlewareListDisablesDefaultsAndWarns(): void
9393
->withHeader('Host', 'evil.example.com')
9494
->withHeader('Origin', 'http://evil.example.com');
9595

96-
$logger = $this->collectingLogger();
96+
$logger = $this->createMock(LoggerInterface::class);
97+
$logger->expects($this->once())
98+
->method('warning')
99+
->with($this->stringContains('empty middleware list'));
97100

98101
$transport = new StreamableHttpTransport(
99102
$request,
@@ -109,11 +112,6 @@ public function testEmptyMiddlewareListDisablesDefaultsAndWarns(): void
109112
$this->assertNotSame(403, $response->getStatusCode());
110113
$this->assertFalse($response->hasHeader('Access-Control-Allow-Origin'));
111114
$this->assertFalse($response->hasHeader('Access-Control-Allow-Methods'));
112-
113-
// Warning was emitted so an operator can spot the bypass in logs.
114-
$warnings = array_filter($logger->records, static fn (array $r): bool => 'warning' === $r['level']);
115-
$this->assertNotEmpty($warnings, 'Expected a warning log for the bypassed defaults.');
116-
$this->assertStringContainsString('empty middleware list', reset($warnings)['message']);
117115
}
118116

119117
#[TestDox('null middleware does not trigger the empty-list warning')]
@@ -123,13 +121,11 @@ public function testNullMiddlewareDoesNotWarn(): void
123121
->createServerRequest('OPTIONS', 'http://localhost/')
124122
->withHeader('Host', 'localhost');
125123

126-
$logger = $this->collectingLogger();
124+
$logger = $this->createMock(LoggerInterface::class);
125+
$logger->expects($this->never())->method('warning');
127126

128127
$transport = new StreamableHttpTransport($request, $this->factory, $this->factory, $logger);
129128
$transport->listen();
130-
131-
$warnings = array_filter($logger->records, static fn (array $r): bool => 'warning' === $r['level']);
132-
$this->assertEmpty($warnings);
133129
}
134130

135131
#[TestDox('custom middleware composes with default stack via spread')]
@@ -278,17 +274,4 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
278274
}
279275
};
280276
}
281-
282-
private function collectingLogger(): object
283-
{
284-
return new class extends AbstractLogger {
285-
/** @var list<array{level: string, message: string}> */
286-
public array $records = [];
287-
288-
public function log($level, \Stringable|string $message, array $context = []): void
289-
{
290-
$this->records[] = ['level' => (string) $level, 'message' => (string) $message];
291-
}
292-
};
293-
}
294277
}

0 commit comments

Comments
 (0)