Passed
Pull Request — master (#209)
by Alexander
26:16 queued 23:43
created

WebAppInfoCollectorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollector() 0 3 1
A collectTestData() 0 9 2
A checkCollectedData() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Unit\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\Web\WebAppInfoCollector;
11
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
12
use Yiisoft\Yii\Http\Event\AfterRequest;
13
use Yiisoft\Yii\Http\Event\BeforeRequest;
14
15
use function sleep;
16
use function usleep;
17
18
final class WebAppInfoCollectorTest extends AbstractCollectorTestCase
19
{
20
    /**
21
     * @param CollectorInterface|WebAppInfoCollector $collector
22
     */
23
    protected function collectTestData(CollectorInterface $collector): void
24
    {
25
        $requestMock = $this->createMock(ServerRequestInterface::class);
26
        $requestMock->method('getAttribute')->willReturn(microtime(true));
27
        $collector->collect(new BeforeRequest($requestMock));
0 ignored issues
show
Bug introduced by
The method collect() does not exist on Yiisoft\Yii\Debug\Collector\CollectorInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Yiisoft\Yii\Debug\Collector\CollectorInterface. ( Ignorable by Annotation )

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

27
        $collector->/** @scrutinizer ignore-call */ 
28
                    collect(new BeforeRequest($requestMock));
Loading history...
28
29
        DIRECTORY_SEPARATOR === '\\' ? sleep(1) : usleep(123_000);
0 ignored issues
show
Bug introduced by
The constant Yiisoft\Yii\Debug\Tests\Unit\Collector\123_000 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
30
31
        $collector->collect(new AfterRequest($this->createMock(ResponseInterface::class)));
32
    }
33
34
    protected function getCollector(): CollectorInterface
35
    {
36
        return new WebAppInfoCollector();
37
    }
38
39
    protected function checkCollectedData(array $data): void
40
    {
41
        parent::checkCollectedData($data);
42
43
        $this->assertGreaterThan(0.122, $data['requestProcessingTime']);
44
    }
45
}
46