Passed
Pull Request — master (#227)
by Alexander
05:16 queued 02:36
created

HttpClientCollectorTest::checkSummaryData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 10
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(
0 ignored issues
show
Bug introduced by
The method collect() does not exist on Yiisoft\Yii\Debug\Collector\CollectorInterface. It seems like you code against a sub-type of said class. However, the method does not exist in Yiisoft\Yii\Debug\Collec...mmaryCollectorInterface or Yiisoft\Yii\Debug\Tests\...\Support\DummyCollector. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        $collector->/** @scrutinizer ignore-call */ 
21
                    collect(
Loading history...
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(
0 ignored issues
show
Bug introduced by
The method collectTotalTime() does not exist on Yiisoft\Yii\Debug\Collector\CollectorInterface. It seems like you code against a sub-type of Yiisoft\Yii\Debug\Collector\CollectorInterface such as Yiisoft\Yii\Debug\Collector\HttpClientCollector. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
        $collector->/** @scrutinizer ignore-call */ 
34
                    collectTotalTime(
Loading history...
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