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
![]() |
|||
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 |