Passed
Push — master ( bafd2f...fc0646 )
by Alexander
02:28
created

MiddlewareCollectorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 11
dl 0
loc 27
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollector() 0 3 1
A checkCollectedData() 0 11 1
A collectTestData() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Collector;
6
7
use Nyholm\Psr7\Response;
8
use Nyholm\Psr7\ServerRequest;
9
use Yiisoft\Middleware\Dispatcher\Event\AfterMiddleware;
10
use Yiisoft\Middleware\Dispatcher\Event\BeforeMiddleware;
11
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
12
use Yiisoft\Yii\Debug\Collector\MiddlewareCollector;
13
use Yiisoft\Yii\Debug\Tests\Support\DummyMiddleware;
14
15
final class MiddlewareCollectorTest extends CollectorTestCase
16
{
17
    /**
18
     * @param \Yiisoft\Yii\Debug\Collector\CollectorInterface|\Yiisoft\Yii\Debug\Collector\MiddlewareCollector $collector
19
     */
20
    protected function collectTestData(CollectorInterface $collector): void
21
    {
22
        $collector->collect(new BeforeMiddleware(new DummyMiddleware(), new ServerRequest('GET', '/test')));
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

22
        $collector->/** @scrutinizer ignore-call */ 
23
                    collect(new BeforeMiddleware(new DummyMiddleware(), new ServerRequest('GET', '/test')));
Loading history...
23
        $collector->collect(new AfterMiddleware(new DummyMiddleware(), new Response(200)));
24
    }
25
26
    protected function getCollector(): CollectorInterface
27
    {
28
        return new MiddlewareCollector();
29
    }
30
31
    protected function checkCollectedData(CollectorInterface $collector): void
32
    {
33
        parent::checkCollectedData($collector);
34
35
        $data = $collector->getCollected();
36
37
        $this->assertEmpty($data['beforeStack']);
38
        $this->assertEmpty($data['afterStack']);
39
        $this->assertNotEmpty($data['actionHandler']);
40
        $this->assertEquals(DummyMiddleware::class, $data['actionHandler']['name']);
41
        $this->assertEquals('GET', $data['actionHandler']['request']->getMethod());
42
    }
43
}
44