8000 [HttpClient] Fix tracing requests made after calling withOptions() · symfony/symfony@06b25c7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 06b25c7

Browse files
[HttpClient] Fix tracing requests made after calling withOptions()
1 parent 98e0fa4 commit 06b25c7

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,18 @@ public function testStopwatchDestruct()
218218
$this->assertCount(1, $events['GET http://localhost:8057']->getPeriods());
219219
$this->assertGreaterThan(0.0, $events['GET http://localhost:8057']->getDuration());
220220
}
221+
222+
public function testWithOptions()
223+
{
224+
$sut = new TraceableHttpClient(new NativeHttpClient());
225+
226+
$sut2 = $sut->withOptions(['base_uri' => 'http://localhost:8057']);
227+
228+
$response = $sut2->request('GET', '/');
229+
230+
$this->assertSame(200, $response->getStatusCode());
231+
$this->assertSame('http://localhost:8057/', $response->getInfo('url'));
232+
233+
$this->assertCount(1, $sut->getTracedRequests());
234+
}
221235
}

src/Symfony/Component/HttpClient/TraceableHttpClient.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@
2727
final class TraceableHttpClient implements HttpClientInterface, ResetInterface, LoggerAwareInterface
2828
{
2929
private $client;
30-
private $tracedRequests = [];
3130
private $stopwatch;
31+
private $tracedRequests;
3232

3333
public function __construct(HttpClientInterface $client, Stopwatch $stopwatch = null)
3434
{
3535
$this->client = $client;
3636
$this->stopwatch = $stopwatch;
37+
$this->tracedRequests = new \ArrayObject();
3738
}
3839

3940
/**
@@ -84,7 +85,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa
8485

8586
public function getTracedRequests(): array
8687
{
87-
return $this->tracedRequests;
88+
return $this->tracedRequests->getArrayCopy();
8889
}
8990

9091
public function reset()
@@ -93,7 +94,7 @@ public function reset()
9394
$this->client->reset();
9495
}
9596

96-
$this->tracedRequests = [];
97+
$this->tracedRequests->exchangeArray([]);
9798
}
9899

99100
/**

0 commit comments

Comments
 (0)
0