Skip to content

Commit

Permalink
Adds the ability to parse json api body schema (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduarguz authored and gmponos committed Aug 23, 2018
1 parent b6c6ab5 commit 6d864a6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Middleware/LoggerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public function getBody(MessageInterface $message)
}

$body = $stream->getContents();
$isJson = preg_grep('/application\/json/', $message->getHeader('Content-Type'));
$isJson = preg_grep('/application\/[\w\.\+]*(json)/', $message->getHeader('Content-Type'));
if (!empty($isJson)) {
$body = json_decode($body, true);
}
Expand Down
26 changes: 26 additions & 0 deletions tests/Unit/LoggerMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,32 @@ public function logTransactionWithJsonResponse()
);
}

/**
* @test
*/
public function logTransactionWithJsonApiResponse()
{
$headers = [
'Content-Type' => 'application/vnd.api+json',
];
$this->appendResponse(200, $headers, '{"status": true, "client": 13000}')
->getClient(['exceptions' => false])
->get('/');

$this->assertCount(2, $this->logger->history);
$this->assertSame('debug', $this->logger->history[0]['level']);
$this->assertSame('Guzzle HTTP request', $this->logger->history[0]['message']);
$this->assertSame('debug', $this->logger->history[1]['level']);
$this->assertSame('Guzzle HTTP response', $this->logger->history[1]['message']);
$this->assertContains(
[
'status' => true,
'client' => 13000,
],
$this->logger->history[1]['context']['response']['body']
);
}

/**
* @test
*/
Expand Down

0 comments on commit 6d864a6

Please sign in to comment.