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

CommandCollectorTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 33
dl 0
loc 63
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A collectTestData() 0 22 1
A checkIndexData() 0 9 2
A getCollector() 0 3 1
A testCollectWithInactiveCollector() 0 7 1
A checkCollectedData() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Collector;
6
7
use Exception;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Event\ConsoleCommandEvent;
10
use Symfony\Component\Console\Event\ConsoleErrorEvent;
11
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
12
use Symfony\Component\Console\Input\StringInput;
13
use Yiisoft\Yii\Console\Output\ConsoleBufferedOutput;
14
use Yiisoft\Yii\Debug\Collector\CollectorInterface;
15
use Yiisoft\Yii\Debug\Collector\CommandCollector;
16
17
final class CommandCollectorTest extends CollectorTestCase
18
{
19
    /**
20
     * @param CollectorInterface|CommandCollector $collector
21
     */
22
    protected function collectTestData(CollectorInterface $collector): void
23
    {
24
        $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\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

24
        $collector->/** @scrutinizer ignore-call */ 
25
                    collect(
Loading history...
25
            new ConsoleCommandEvent(
26
                new Command('test'),
27
                new StringInput('test'),
28
                new ConsoleBufferedOutput()
29
            )
30
        );
31
        $collector->collect(
32
            new ConsoleErrorEvent(
33
                new StringInput('test1'),
34
                new ConsoleBufferedOutput(),
35
                new Exception()
36
            )
37
        );
38
        $collector->collect(
39
            new ConsoleTerminateEvent(
40
                new Command('test1'),
41
                new StringInput('test1'),
42
                new ConsoleBufferedOutput(),
43
                0
44
            )
45
        );
46
    }
47
48
    public function testCollectWithInactiveCollector(): void
49
    {
50
        $collector = $this->getCollector();
51
        $this->collectTestData($collector);
52
53
        $collected = $collector->getCollected();
54
        $this->assertEmpty($collected);
55
    }
56
57
    protected function getCollector(): CollectorInterface
58
    {
59
        return new CommandCollector();
60
    }
61
62
    protected function checkCollectedData(CollectorInterface $collector): void
63
    {
64
        parent::checkCollectedData($collector);
65
        $collected = $collector->getCollected();
66
        $this->assertCount(3, $collected);
67
        $this->assertEquals('test', $collected[ConsoleCommandEvent::class]['input']);
68
        $this->assertEmpty($collected[ConsoleCommandEvent::class]['output']);
69
    }
70
71
    protected function checkIndexData(CollectorInterface $collector): void
72
    {
73
        parent::checkIndexData($collector);
74
        if ($collector instanceof CommandCollector) {
75
            $this->assertArrayHasKey('command', $collector->getIndexData());
76
            $this->assertArrayHasKey('input', $collector->getIndexData()['command']);
77
            $this->assertArrayHasKey('class', $collector->getIndexData()['command']);
78
            $this->assertEquals('test1', $collector->getIndexData()['command']['input']);
79
            $this->assertEquals(null, $collector->getIndexData()['command']['class']);
80
        }
81
    }
82
}
83