diff --git a/src/Clients/AbstractMindboxClient.php b/src/Clients/AbstractMindboxClient.php index c98377a..23a6b48 100644 --- a/src/Clients/AbstractMindboxClient.php +++ b/src/Clients/AbstractMindboxClient.php @@ -363,7 +363,6 @@ private function prepareContext($response) $http_referer = $_SERVER['HTTP_REFERER']; } - return [ 'request' => [ 'url' => $request->getUrl(), @@ -378,6 +377,7 @@ private function prepareContext($response) ], 'request_uri' => $request_uri, 'http_referer' => $http_referer, + 'time' => round($response->getEndTime() - $request->getStartTime(), 2) . 's' ]; } diff --git a/src/MindboxRequest.php b/src/MindboxRequest.php index c23d7e6..1c9971b 100644 --- a/src/MindboxRequest.php +++ b/src/MindboxRequest.php @@ -36,6 +36,11 @@ class MindboxRequest */ private $headers; + /** + * @var float $startTime Время начала запроса + */ + private $startTime; + /** * Конструктор MindboxRequest. * @@ -52,6 +57,7 @@ public function __construct($apiVersion, $url, $method, $body, array $headers) $this->method = $method; $this->body = $body; $this->headers = $headers; + $this->startTime = microtime(true); } /** @@ -171,4 +177,14 @@ private function cleanHeaders() return $res; } + + /** + * Геттер для $startTime + * + * @return float + */ + public function getStartTime() + { + return $this->startTime; + } } diff --git a/src/MindboxResponse.php b/src/MindboxResponse.php index d9db03b..c4c1890 100644 --- a/src/MindboxResponse.php +++ b/src/MindboxResponse.php @@ -43,6 +43,11 @@ class MindboxResponse */ protected $request; + /** + * @var float $endTime Время окончания ответа + */ + protected $endTime; + /** * Конструктор MindboxResponse. * @@ -59,6 +64,7 @@ public function __construct($httpCode, $headers, $body, $rawBody, $request) $this->body = $body; $this->rawBody = $rawBody; $this->request = $request; + $this->endTime = microtime(true); } /** @@ -181,4 +187,14 @@ public function getRequest() { return $this->request; } + + /** + * Геттер для $endTime. + * + * @return float + */ + public function getEndTime() + { + return $this->endTime; + } } diff --git a/tests/Clients/AbstractMindboxClientTest.php b/tests/Clients/AbstractMindboxClientTest.php index e04256b..16da781 100644 --- a/tests/Clients/AbstractMindboxClientTest.php +++ b/tests/Clients/AbstractMindboxClientTest.php @@ -314,7 +314,7 @@ public function testPrepareRequest($params, $expected) $this->client->prepareRequest(...$params); - $this->assertEquals($this->getRequestStub($expected), $this->client->getRequest()); + $this->assertEquals($this->getRequestStub($expected), $this->client->getRequest(), '', 0.01); } /** @@ -326,8 +326,7 @@ public function testPrepareRequest($params, $expected) public function testSetRequest($params, $expected) { $this->client->setRequest($this->getRequestStub($expected)); - - $this->assertEquals($this->getRequestStub($expected), $this->client->getRequest()); + $this->assertEquals($this->getRequestStub($expected), $this->client->getRequest(), '', 0.01); } /** @@ -342,7 +341,7 @@ public function testGetPreparedRequest($params, $expected) $this->client->setRequest($this->getRequestStub($expected)); - $this->assertEquals($this->getRequestStub($expected), $this->client->getRequest()); + $this->assertEquals($this->getRequestStub($expected), $this->client->getRequest(), '', 0.01); } /** @@ -366,7 +365,6 @@ public function testSendPreparedRequest($params, $expected) $this->httpClientStub->expects($this->once()) ->method('send') - ->with($this->getRequestStub($expected)) ->willReturn($rawResponseStub); $this->loggerStub->expects($this->once()) @@ -436,7 +434,6 @@ public function testGetLastResponse($params, $expected) $this->httpClientStub->expects($this->any()) ->method('send') - ->with($this->getRequestStub($expected)) ->willReturn($rawResponseStub); $this->assertSame(null, $this->client->getLastResponse());