8000 [HttpClient] Move Http clients data collecting at a late level · symfony/symfony@692a631 · GitHub
[go: up one dir, main page]

Skip to content

Commit 692a631

Browse files
pforesifabpot
authored andcommitted
[HttpClient] Move Http clients data collecting at a late level
1 parent 2f62c4a commit 692a631

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public function registerClient(string $name, TraceableHttpClient $client)
3737
* {@inheritdoc}
3838
*/
3939
public function collect(Request $request, Response $response, \Throwable $exception = null)
40+
{
41+
}
42+
43+
public function lateCollect()
4044
{
4145
$this->reset();
4246

@@ -50,12 +54,7 @@ public function collect(Request $request, Response $response, \Throwable $except
5054

5155
$this->data['request_count'] += \count($traces);
5256
$this->data['error_count'] += $errorCount;
53-
}
54-
}
5557

56-
public function lateCollect()
57-
{
58-
foreach ($this->clients as $client) {
5958
$client->reset();
6059
}
6160
}

src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
use Symfony\Component\HttpClient\DataCollector\HttpClientDataCollector;
1616
use Symfony\Component\HttpClient\NativeHttpClient;
1717
use Symfony\Component\HttpClient\TraceableHttpClient;
18-
use Symfony\Component\HttpFoundation\Request;
19-
use Symfony\Component\HttpFoundation\Response;
2018
use Symfony\Contracts\HttpClient\Test\TestHttpServer;
2119

2220
class HttpClientDataCollectorTest extends TestCase
@@ -50,7 +48,7 @@ public function testItCollectsRequestCount()
5048
$sut->registerClient('http_client2', $httpClient2);
5149
$sut->registerClient('http_client3', $httpClient3);
5250
$this->assertEquals(0, $sut->getRequestCount());
53-
$sut->collect(new Request(), new Response());
51+
$sut->lateCollect();
5452
$this->assertEquals(3, $sut->getRequestCount());
5553
}
5654

@@ -79,7 +77,7 @@ public function testItCollectsErrorCount()
7977
$sut->registerClient('http_client2', $httpClient2);
8078
$sut->registerClient('http_client3', $httpClient3);
8179
$this->assertEquals(0, $sut->getErrorCount());
82-
$sut->collect(new Request(), new Response());
80+
$sut->lateCollect();
8381
$this->assertEquals(1, $sut->getErrorCount());
8482
}
8583

@@ -108,7 +106,7 @@ public function testItCollectsErrorCountByClient()
108106
$sut->registerClient('http_client2', $httpClient2);
109107
$sut->registerClient('http_client3', $httpClient3);
110108
$this->assertEquals([], $sut->getClients());
111-
$sut->collect(new Request(), new Response());
109+
$sut->lateCollect();
112110
$collectedData = $sut->getClients();
113111
$this->assertEquals(0, $collectedData['http_client1']['error_count']);
114112
$this->assertEquals(1, $collectedData['http_client2']['error_count']);
@@ -140,7 +138,7 @@ public function testItCollectsTracesByClient()
140138
$sut->registerClient('http_client2', $httpClient2);
141139
$sut->registerClient('http_client3', $httpClient3);
142140
$this->assertEquals([], $sut->getClients());
143-
$sut->collect(new Request(), new Response());
141+
$sut->lateCollect();
144142
$collectedData = $sut->getClients();
145143
$this->assertCount(2, $collectedData['http_client1']['traces']);
146144
$this->assertCount(1, $collectedData['http_client2']['traces']);
@@ -157,7 +155,7 @@ public function testItIsEmptyAfterReset()
157155
]);
158156
$sut = new HttpClientDataCollector();
159157
$sut->registerClient('http_client1', $httpClient1);
160-
$sut->collect(new Request(), new Response());
158+
$sut->lateCollect();
161159
$collectedData = $sut->getClients();
162160
$this->assertCount(1, $collectedData['http_client1']['traces']);
163161
$sut->reset();

0 commit comments

Comments
 (0)
0