1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Debug\Tests\Unit\Collector; |
6
|
|
|
|
7
|
|
|
use GuzzleHttp\Psr7\Response; |
8
|
|
|
use Yiisoft\Yii\Debug\Collector\CollectorInterface; |
9
|
|
|
use Yiisoft\Yii\Debug\Collector\HttpClientCollector; |
10
|
|
|
use Yiisoft\Yii\Debug\Collector\TimelineCollector; |
11
|
|
|
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase; |
12
|
|
|
|
13
|
|
|
final class HttpClientCollectorTest extends AbstractCollectorTestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param CollectorInterface|HttpClientCollector $collector |
17
|
|
|
*/ |
18
|
|
|
protected function collectTestData(CollectorInterface $collector): void |
19
|
|
|
{ |
20
|
|
|
$collector->collect( |
|
|
|
|
21
|
|
|
new \GuzzleHttp\Psr7\Request('GET', 'http://example.com'), |
22
|
|
|
startTime: 10.10, |
23
|
|
|
line: 'file1:123', |
24
|
|
|
uniqueId: 'test1', |
25
|
|
|
); |
26
|
|
|
$collector->collect( |
27
|
|
|
new \GuzzleHttp\Psr7\Request('GET', 'http://yiiframework.com'), |
28
|
|
|
startTime: 12.10, |
29
|
|
|
line: 'file2:555', |
30
|
|
|
uniqueId: 'test2' |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
$collector->collectTotalTime( |
|
|
|
|
34
|
|
|
new Response(200, [], 'test'), |
35
|
|
|
endTime: 13.10, |
36
|
|
|
uniqueId: 'test1' |
37
|
|
|
); |
38
|
|
|
$collector->collectTotalTime( |
39
|
|
|
new Response(200, [], 'test'), |
40
|
|
|
endTime: 12.20, |
41
|
|
|
uniqueId: 'test2' |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function getCollector(): CollectorInterface |
46
|
|
|
{ |
47
|
|
|
return new HttpClientCollector(new TimelineCollector()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function checkCollectedData(array $data): void |
51
|
|
|
{ |
52
|
|
|
parent::checkCollectedData($data); |
53
|
|
|
|
54
|
|
|
$this->assertCount(2, $data); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function checkSummaryData(array $data): void |
58
|
|
|
{ |
59
|
|
|
parent::checkSummaryData($data); |
60
|
|
|
$this->assertCount(1, $data); |
61
|
|
|
$this->assertArrayHasKey('http', $data); |
62
|
|
|
$this->assertCount(2, $data['http']); |
63
|
|
|
$this->assertArrayHasKey('count', $data['http']); |
64
|
|
|
$this->assertArrayHasKey('totalTime', $data['http']); |
65
|
|
|
|
66
|
|
|
$this->assertEquals(2, $data['http']['count']); |
67
|
|
|
$this->assertEquals(3.1, round($data['http']['totalTime'], 1)); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|