Passed
Push — master ( f7ef7a...65c26d )
by Dmitriy
02:46
created

tests/Collector/CommandCollectorTest.php (1 issue)

Labels
Severity
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\Console\CommandCollector;
16
17
final class CommandCollectorTest extends AbstractCollectorTestCase
18
{
19
    /**
20
     * @param CollectorInterface|CommandCollector $collector
21
     */
22
    protected function collectTestData(CollectorInterface $collector): void
23
    {
24
        $collector->collect(
0 ignored issues
show
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\Queue\QueueCollector or Yiisoft\Yii\Debug\Collec...abase\DatabaseCollector. 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(array $data): void
63
    {
64
        parent::checkCollectedData($data);
65
        $this->assertCount(3, $data);
66
        $this->assertEquals('test', $data[ConsoleCommandEvent::class]['input']);
67
        $this->assertEmpty($data[ConsoleCommandEvent::class]['output']);
68
    }
69
70
    protected function checkIndexData(array $data): void
71
    {
72
        $this->assertArrayHasKey('command', $data);
73
        $this->assertArrayHasKey('input', $data['command']);
74
        $this->assertArrayHasKey('class', $data['command']);
75
        $this->assertEquals('test1', $data['command']['input']);
76
        $this->assertEquals(null, $data['command']['class']);
77
    }
78
}
79