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