Skip to content

Commit

Permalink
Merge pull request #37 from intensa/master
Browse files Browse the repository at this point in the history
Release 1.0.4
  • Loading branch information
IvanShishkin authored Oct 14, 2021
2 parents 2d0c1a3 + 226599d commit f5ff507
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Clients/AbstractMindboxClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ private function prepareContext($response)
$http_referer = $_SERVER['HTTP_REFERER'];
}


return [
'request' => [
'url' => $request->getUrl(),
Expand All @@ -378,6 +377,7 @@ private function prepareContext($response)
],
'request_uri' => $request_uri,
'http_referer' => $http_referer,
'time' => round($response->getEndTime() - $request->getStartTime(), 2) . 's'
];
}

Expand Down
16 changes: 16 additions & 0 deletions src/MindboxRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class MindboxRequest
*/
private $headers;

/**
* @var float $startTime Время начала запроса
*/
private $startTime;

/**
* Конструктор MindboxRequest.
*
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -171,4 +177,14 @@ private function cleanHeaders()

return $res;
}

/**
* Геттер для $startTime
*
* @return float
*/
public function getStartTime()
{
return $this->startTime;
}
}
16 changes: 16 additions & 0 deletions src/MindboxResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class MindboxResponse
*/
protected $request;

/**
* @var float $endTime Время окончания ответа
*/
protected $endTime;

/**
* Конструктор MindboxResponse.
*
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -181,4 +187,14 @@ public function getRequest()
{
return $this->request;
}

/**
* Геттер для $endTime.
*
* @return float
*/
public function getEndTime()
{
return $this->endTime;
}
}
9 changes: 3 additions & 6 deletions tests/Clients/AbstractMindboxClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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())
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit f5ff507

Please sign in to comment.