Completed
Push — master ( 9dfaca...8ef6fd )
by Alessandro
14s
created

DebugPrinter::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 2
cts 2
cp 1
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Paraunit\Printer;
5
6
use Paraunit\Lifecycle\ProcessEvent;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9
/**
10
 * Class DebugPrinter
11
 * @package Paraunit\Printer
12
 */
13
class DebugPrinter extends AbstractPrinter implements EventSubscriberInterface
14
{
15 2
    public static function getSubscribedEvents(): array
16
    {
17
        return [
18 2
            ProcessEvent::PROCESS_STARTED => 'onProcessStarted',
19
            ProcessEvent::PROCESS_TERMINATED => 'onProcessTerminated',
20
            ProcessEvent::PROCESS_PARSING_COMPLETED => ['onProcessParsingCompleted', 1],
21
            ProcessEvent::PROCESS_TO_BE_RETRIED => 'onProcessToBeRetried',
22
        ];
23
    }
24
25 2
    public function onProcessStarted(ProcessEvent $event)
26
    {
27 2
        $process = $event->getProcess();
28
29 2
        $this->getOutput()->writeln('PROCESS STARTED: ' . $process->getFilename());
30 2
        $this->getOutput()->writeln($process->getCommandLine());
31 2
        $this->getOutput()->writeln('');
32
    }
33
34 2
    public function onProcessTerminated(ProcessEvent $event)
35
    {
36 2
        $process = $event->getProcess();
37
38 2
        $this->getOutput()->writeln('');
39 2
        $this->getOutput()->writeln('PROCESS TERMINATED: ' . $process->getFilename());
40 2
        $this->getOutput()->writeln(' - with class name: ' . $process->getTestClassName() ?? 'N/A');
41 2
        $this->getOutput()->writeln('');
42
    }
43
44 2
    public function onProcessParsingCompleted()
45
    {
46 2
        $this->getOutput()->write('PROCESS PARSING COMPLETED -- RESULTS: ');
47
    }
48
49 2
    public function onProcessToBeRetried(ProcessEvent $event)
50
    {
51 2
        $process = $event->getProcess();
52
53 2
        $this->getOutput()->writeln('');
54 2
        $this->getOutput()->writeln('PROCESS TO BE RETRIED: ' . $process->getFilename());
55
    }
56
}
57