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 AbstractCollectorTestCase |
||
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
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 |