Passed
Push — master ( 7bc6a4...bace86 )
by Dmitriy
06:54 queued 04:27
created

CommandCollectorTest::getCollector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Tests\Unit\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\Console\CommandCollector;
16
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
17
18
final class CommandCollectorTest extends AbstractCollectorTestCase
19
{
20
    /**
21
     * @param CollectorInterface|CommandCollector $collector
22
     */
23
    protected function collectTestData(CollectorInterface $collector): void
24
    {
25
        $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. 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

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