Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions spec/StopwatchPluginSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Http\Promise\RejectedPromise;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use PhpSpec\ObjectBehavior;

Expand All @@ -27,13 +29,14 @@ function it_is_a_plugin()
$this->shouldImplement('Http\Client\Common\Plugin');
}

function it_records_event(Stopwatch $stopwatch, RequestInterface $request, ResponseInterface $response)
function it_records_event(Stopwatch $stopwatch, RequestInterface $request, ResponseInterface $response, UriInterface $uri)
{
$request->getMethod()->willReturn('GET');
$request->getRequestTarget()->willReturn('/');
$request->getUri()->willReturn($uri);
$uri->__toString()->willReturn('http://foo.com/bar');

$stopwatch->start('GET /', 'php_http.request')->shouldBeCalled();
$stopwatch->stop('GET /', 'php_http.request')->shouldBeCalled();
$stopwatch->start('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled();
$stopwatch->stop('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled();

$next = function (RequestInterface $request) use ($response) {
return new FulfilledPromise($response->getWrappedObject());
Expand All @@ -42,13 +45,14 @@ function it_records_event(Stopwatch $stopwatch, RequestInterface $request, Respo
$this->handleRequest($request, $next, function () {});
}

function it_records_event_on_error(Stopwatch $stopwatch, RequestInterface $request)
function it_records_event_on_error(Stopwatch $stopwatch, RequestInterface $request, UriInterface $uri)
{
$request->getMethod()->willReturn('GET');
$request->getRequestTarget()->willReturn('/');
$request->getUri()->willReturn($uri);
$uri->__toString()->willReturn('http://foo.com/bar');

$stopwatch->start('GET /', 'php_http.request')->shouldBeCalled();
$stopwatch->stop('GET /', 'php_http.request')->shouldBeCalled();
$stopwatch->start('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled();
$stopwatch->stop('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled();

$next = function (RequestInterface $request) {
return new RejectedPromise(new NetworkException('', $request));
Expand Down
2 changes: 1 addition & 1 deletion src/StopwatchPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
*/
private function getStopwatchEventName(RequestInterface $request)
{
return sprintf('%s %s', $request->getMethod(), $request->getRequestTarget());
return sprintf('%s %s', $request->getMethod(), $request->getUri()->__toString());
}
}