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 CollectorTestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @param CollectorInterface|CommandCollector $collector |
21
|
|
|
*/ |
22
|
|
|
protected function collectTestData(CollectorInterface $collector): void |
23
|
|
|
{ |
24
|
|
|
$collector->collect( |
|
|
|
|
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(CollectorInterface $collector): void |
63
|
|
|
{ |
64
|
|
|
parent::checkCollectedData($collector); |
65
|
|
|
$collected = $collector->getCollected(); |
66
|
|
|
$this->assertCount(3, $collected); |
67
|
|
|
$this->assertEquals('test', $collected[ConsoleCommandEvent::class]['input']); |
68
|
|
|
$this->assertEmpty($collected[ConsoleCommandEvent::class]['output']); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function checkIndexData(CollectorInterface $collector): void |
72
|
|
|
{ |
73
|
|
|
parent::checkIndexData($collector); |
74
|
|
|
if ($collector instanceof CommandCollector) { |
75
|
|
|
$this->assertArrayHasKey('command', $collector->getIndexData()); |
76
|
|
|
$this->assertArrayHasKey('input', $collector->getIndexData()['command']); |
77
|
|
|
$this->assertArrayHasKey('class', $collector->getIndexData()['command']); |
78
|
|
|
$this->assertEquals('test1', $collector->getIndexData()['command']['input']); |
79
|
|
|
$this->assertEquals(null, $collector->getIndexData()['command']['class']); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|