Passed
Pull Request — master (#156)
by Wilmer
06:05 queued 03:57
created

WebAppInfoCollectorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 3
b 0
f 0
dl 0
loc 27
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A collectTestData() 0 9 1
A getCollector() 0 3 1
A checkCollectedData() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Collector;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
10
use Yiisoft\Yii\Debug\Collector\WebAppInfoCollector;
11
use Yiisoft\Yii\Http\Event\AfterRequest;
12
use Yiisoft\Yii\Http\Event\BeforeRequest;
13
14
use function microtime;
15
use function time_sleep_until;
16
17
final class WebAppInfoCollectorTest extends CollectorTestCase
18
{
19
    /**
20
     * @param WebAppInfoCollector|\Yiisoft\Yii\Debug\Collector\CollectorInterface $collector
21
     */
22
    protected function collectTestData(CollectorInterface $collector): void
23
    {
24
        $requestMock = $this->createMock(ServerRequestInterface::class);
25
        $requestMock->method('getAttribute')->willReturn(microtime(true));
26
        $collector->collect(new BeforeRequest($requestMock));
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\Collector\QueueCollector. 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

26
        $collector->/** @scrutinizer ignore-call */ 
27
                    collect(new BeforeRequest($requestMock));
Loading history...
27
28
        time_sleep_until(microtime(true) + 0.123);
29
30
        $collector->collect(new AfterRequest($this->createMock(ResponseInterface::class)));
31
    }
32
33
    protected function getCollector(): CollectorInterface
34
    {
35
        return new WebAppInfoCollector();
36
    }
37
38
    protected function checkCollectedData(CollectorInterface $collector): void
39
    {
40
        parent::checkCollectedData($collector);
41
        $data = $collector->getCollected();
42
43
        $this->assertGreaterThan(0.122, $data['requestProcessingTime']);
44
    }
45
}
46