Skip to content

Commit b71a040

Browse files
committed
Improved tests and correctness.
1 parent 09c6a39 commit b71a040

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

spec/LoggerPluginSpec.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function it_logs_request_and_response(
4545
"Received response:\n200 OK 1.1\n\nfor request:\nGET / 1.1",
4646
Argument::that(
4747
function(array $context) use ($request, $response) {
48-
return $context['request'] === $request
49-
&& $context['response'] === $response
48+
return $context['request'] === $request->getWrappedObject()
49+
&& $context['response'] === $response->getWrappedObject()
5050
&& is_int($context['milliseconds'])
5151
;
5252
}
@@ -71,7 +71,7 @@ function it_logs_exception(LoggerInterface $logger, Formatter $formatter, Reques
7171
"Error:\nCannot connect\nwhen sending request:\nGET / 1.1",
7272
Argument::that(
7373
function(array $context) use ($request, $exception) {
74-
return $context['request'] === $request
74+
return $context['request'] === $request->getWrappedObject()
7575
&& $context['exception'] === $exception
7676
&& is_int($context['milliseconds'])
7777
;
@@ -102,8 +102,8 @@ function it_logs_response_within_exception(
102102
"Error:\nForbidden\nwith response:\n403 Forbidden 1.1\n\nwhen sending request:\nGET / 1.1",
103103
Argument::that(
104104
function(array $context) use ($request, $response, $exception) {
105-
return $context['request'] === $request
106-
&& $context['response'] === $response
105+
return $context['request'] === $request->getWrappedObject()
106+
&& $context['response'] === $response->getWrappedObject()
107107
&& $context['exception'] === $exception
108108
&& is_int($context['milliseconds'])
109109
;

src/LoggerPlugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public function __construct(LoggerInterface $logger, Formatter $formatter = null
3232
*/
3333
public function handleRequest(RequestInterface $request, callable $next, callable $first)
3434
{
35-
$start = microtime();
35+
$start = microtime(true);
3636
$this->logger->info(sprintf("Sending request:\n%s", $this->formatter->formatRequest($request)), ['request' => $request]);
3737

3838
return $next($request)->then(function (ResponseInterface $response) use ($request, $start) {
39-
$milliseconds = round(microtime() - $start / 1000);
39+
$milliseconds = (int) round((microtime(true) - $start) * 1000);
4040
$this->logger->info(
4141
sprintf("Received response:\n%s\n\nfor request:\n%s", $this->formatter->formatResponse($response), $this->formatter->formatRequest($request)),
4242
[
@@ -48,7 +48,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
4848

4949
return $response;
5050
}, function (Exception $exception) use ($request, $start) {
51-
$milliseconds = round(microtime() - $start / 1000);
51+
$milliseconds = (int) round((microtime(true) - $start) * 1000);
5252
if ($exception instanceof Exception\HttpException) {
5353
$this->logger->error(
5454
sprintf("Error:\n%s\nwith response:\n%s\n\nwhen sending request:\n%s", $exception->getMessage(), $this->formatter->formatResponse($exception->getResponse()), $this->formatter->formatRequest($request)),

0 commit comments

Comments
 (0)