testCollectWithInactiveCollector()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
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\Collector\TimelineCollector;
17
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
18
19
final class CommandCollectorTest extends AbstractCollectorTestCase
20
{
21
    /**
22
     * @param CollectorInterface|CommandCollector $collector
23
     */
24
    protected function collectTestData(CollectorInterface $collector): void
25
    {
26
        $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 or Yiisoft\Yii\Debug\Tests\...\Support\DummyCollector. 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(
Loading history...
27
            new ConsoleCommandEvent(
28
                new Command('test'),
29
                new StringInput('test'),
30
                new ConsoleBufferedOutput()
31
            )
32
        );
33
        $collector->collect(
34
            new ConsoleErrorEvent(
35
                new StringInput('test1'),
36
                new ConsoleBufferedOutput(),
37
                new Exception()
38
            )
39
        );
40
        $collector->collect(
41
            new ConsoleTerminateEvent(
42
                new Command('test1'),
43
                new StringInput('test1'),
44
                new ConsoleBufferedOutput(),
45
                0
46
            )
47
        );
48
    }
49
50
    public function testCollectWithInactiveCollector(): void
51
    {
52
        $collector = $this->getCollector();
53
        $this->collectTestData($collector);
54
55
        $collected = $collector->getCollected();
56
        $this->assertEmpty($collected);
57
    }
58
59
    protected function getCollector(): CollectorInterface
60
    {
61
        return new CommandCollector(new TimelineCollector());
62
    }
63
64
    protected function checkCollectedData(array $data): void
65
    {
66
        parent::checkCollectedData($data);
67
        $this->assertCount(3, $data);
68
        $this->assertEquals('test', $data[ConsoleCommandEvent::class]['input']);
69
        $this->assertEmpty($data[ConsoleCommandEvent::class]['output']);
70
    }
71
72
    protected function checkSummaryData(array $data): void
73
    {
74
        $this->assertArrayHasKey('command', $data);
75
        $this->assertArrayHasKey('input', $data['command']);
76
        $this->assertArrayHasKey('class', $data['command']);
77
        $this->assertEquals('test1', $data['command']['input']);
78
        $this->assertEquals(null, $data['command']['class']);
79
    }
80
}
81