diff --git a/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php b/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php index 96f0a64c3bb0e..5f20e1989dfa1 100755 --- a/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php @@ -218,4 +218,18 @@ public function testStopwatchDestruct() $this->assertCount(1, $events['GET http://localhost:8057']->getPeriods()); $this->assertGreaterThan(0.0, $events['GET http://localhost:8057']->getDuration()); } + + public function testWithOptions() + { + $sut = new TraceableHttpClient(new NativeHttpClient()); + + $sut2 = $sut->withOptions(['base_uri' => 'http://localhost:8057']); + + $response = $sut2->request('GET', '/'); + + $this->assertSame(200, $response->getStatusCode()); + $this->assertSame('http://localhost:8057/', $response->getInfo('url')); + + $this->assertCount(1, $sut->getTracedRequests()); + } } diff --git a/src/Symfony/Component/HttpClient/TraceableHttpClient.php b/src/Symfony/Component/HttpClient/TraceableHttpClient.php index bc842115900de..76c9282243df3 100644 --- a/src/Symfony/Component/HttpClient/TraceableHttpClient.php +++ b/src/Symfony/Component/HttpClient/TraceableHttpClient.php @@ -27,13 +27,14 @@ final class TraceableHttpClient implements HttpClientInterface, ResetInterface, LoggerAwareInterface { private $client; - private $tracedRequests = []; private $stopwatch; + private $tracedRequests; public function __construct(HttpClientInterface $client, Stopwatch $stopwatch = null) { $this->client = $client; $this->stopwatch = $stopwatch; + $this->tracedRequests = new \ArrayObject(); } /** @@ -84,7 +85,7 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa public function getTracedRequests(): array { - return $this->tracedRequests; + return $this->tracedRequests->getArrayCopy(); } public function reset() @@ -93,7 +94,7 @@ public function reset() $this->client->reset(); } - $this->tracedRequests = []; + $this->tracedRequests->exchangeArray([]); } /**