diff --git a/spec/StopwatchPluginSpec.php b/spec/StopwatchPluginSpec.php index e1d55e7..ba80ba6 100644 --- a/spec/StopwatchPluginSpec.php +++ b/spec/StopwatchPluginSpec.php @@ -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; @@ -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()); @@ -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)); diff --git a/src/StopwatchPlugin.php b/src/StopwatchPlugin.php index 6af8a2c..8e3054a 100644 --- a/src/StopwatchPlugin.php +++ b/src/StopwatchPlugin.php @@ -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()); } }