Skip to content

Commit cf58b1a

Browse files
Nyholmdbu
authored andcommitted
Show full URL in event name (#2)
Show full URL in event name
1 parent a485d38 commit cf58b1a

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

spec/StopwatchPluginSpec.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use Http\Promise\RejectedPromise;
88
use Psr\Http\Message\RequestInterface;
99
use Psr\Http\Message\ResponseInterface;
10+
use Psr\Http\Message\StreamInterface;
11+
use Psr\Http\Message\UriInterface;
1012
use Symfony\Component\Stopwatch\Stopwatch;
1113
use PhpSpec\ObjectBehavior;
1214

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

30-
function it_records_event(Stopwatch $stopwatch, RequestInterface $request, ResponseInterface $response)
32+
function it_records_event(Stopwatch $stopwatch, RequestInterface $request, ResponseInterface $response, UriInterface $uri)
3133
{
3234
$request->getMethod()->willReturn('GET');
33-
$request->getRequestTarget()->willReturn('/');
35+
$request->getUri()->willReturn($uri);
36+
$uri->__toString()->willReturn('http://foo.com/bar');
3437

35-
$stopwatch->start('GET /', 'php_http.request')->shouldBeCalled();
36-
$stopwatch->stop('GET /', 'php_http.request')->shouldBeCalled();
38+
$stopwatch->start('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled();
39+
$stopwatch->stop('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled();
3740

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

45-
function it_records_event_on_error(Stopwatch $stopwatch, RequestInterface $request)
48+
function it_records_event_on_error(Stopwatch $stopwatch, RequestInterface $request, UriInterface $uri)
4649
{
4750
$request->getMethod()->willReturn('GET');
48-
$request->getRequestTarget()->willReturn('/');
51+
$request->getUri()->willReturn($uri);
52+
$uri->__toString()->willReturn('http://foo.com/bar');
4953

50-
$stopwatch->start('GET /', 'php_http.request')->shouldBeCalled();
51-
$stopwatch->stop('GET /', 'php_http.request')->shouldBeCalled();
54+
$stopwatch->start('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled();
55+
$stopwatch->stop('GET http://foo.com/bar', 'php_http.request')->shouldBeCalled();
5256

5357
$next = function (RequestInterface $request) {
5458
return new RejectedPromise(new NetworkException('', $request));

src/StopwatchPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
5858
*/
5959
private function getStopwatchEventName(RequestInterface $request)
6060
{
61-
return sprintf('%s %s', $request->getMethod(), $request->getRequestTarget());
61+
return sprintf('%s %s', $request->getMethod(), $request->getUri()->__toString());
6262
}
6363
}

0 commit comments

Comments
 (0)