Skip to content

Commit

Permalink
Change test to use logging test handler
Browse files Browse the repository at this point in the history
  • Loading branch information
cspray committed Feb 17, 2024
1 parent 3dbc7e8 commit 874bff4
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions test/Integration/HttpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use org\bovigo\vfs\vfsStream as VirtualFilesystem;
use org\bovigo\vfs\vfsStreamDirectory as VirtualDirectory;
use org\bovigo\vfs\vfsStreamWrapper as VirtualStream;
use PHPUnit\Framework\Constraint\StringMatchesFormatDescription;
use Ramsey\Uuid\Uuid;

class HttpServerTest extends AsyncTestCase {
Expand Down Expand Up @@ -127,22 +128,19 @@ public function testCorrectAccessLogOutputSendToStdout() : void {
$request = new Request('http://localhost:4200/hello/world');
$client->request($request);

$expected = <<<TEXT
%a
%a labrador.web-server.INFO: "GET http://localhost:%d/hello/world" 200 "OK" HTTP/1.1 127.0.0.1:%d on 127.0.0.1:%d {"request":{"method":"GET","uri":"http://localhost:4200/hello/world","protocolVersion":"1.1","local":"127.0.0.1:%d","remote":"127.0.0.1:%d"},"response":{"status":200,"reason":"OK"}} []
%a
TEXT;

$handler = self::$container->get(DummyMonologInitializer::class)->testHandler;
self::assertInstanceOf(TestHandler::class, $handler);

self::assertStringMatchesFormat(
$expected,
join(
PHP_EOL,
array_map(static fn(LogRecord $logRecord) => $logRecord->formatted, $handler->getRecords())
)
);
self::assertTrue($handler->hasInfoThatPasses(static function (LogRecord $record) {
$expected = <<<TEXT
%a labrador.web-server.INFO: "GET http://localhost:%d/hello/world" 200 "OK" HTTP/1.1 127.0.0.1:%d on 127.0.0.1:%d {"request":{"method":"GET","uri":"http://localhost:4200/hello/world","protocolVersion":"1.1","local":"127.0.0.1:%d","remote":"127.0.0.1:%d"},"response":{"status":200,"reason":"OK"}} []
TEXT;
return (new StringMatchesFormatDescription($expected))->evaluate(
other: $record->formatted,
returnResult: true
);
}));
}

public function testExceptionThrowHasCorrectLogOutputSentToStdout() : void {
Expand Down

0 comments on commit 874bff4

Please sign in to comment.