1
|
|
|
<?php |
2
|
|
|
namespace Peridot\Reporter; |
3
|
|
|
|
4
|
|
|
use Evenement\EventEmitterInterface; |
5
|
|
|
use Peridot\Configuration; |
6
|
|
|
use Peridot\Core\HasEventEmitterTrait; |
7
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Combines multiple reporters. |
12
|
|
|
* |
13
|
|
|
* @package Peridot\Reporter |
14
|
|
|
*/ |
15
|
|
|
class CompositeReporter extends AbstractBaseReporter |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private $reporters; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param array $reporters |
24
|
|
|
* @param Configuration $configuration |
25
|
|
|
* @param OutputInterface $output |
26
|
|
|
* @param EventEmitterInterface $eventEmitter |
27
|
|
|
*/ |
28
|
|
|
public function __construct( |
29
|
|
|
array $reporters, |
30
|
|
|
Configuration $configuration, |
31
|
|
|
OutputInterface $output, |
32
|
|
|
EventEmitterInterface $eventEmitter |
33
|
|
|
) { |
34
|
|
|
$this->reporters = $reporters; |
35
|
|
|
|
36
|
|
|
parent::__construct($configuration, $output, $eventEmitter); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Return the wrapped reporters. |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function getReporters() |
45
|
|
|
{ |
46
|
|
|
return $this->reporters; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Initialize reporter. Setup and listen for runner events. |
51
|
|
|
* |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function init() |
55
|
|
|
{ |
56
|
|
|
$this->eventEmitter->on('runner.end', [$this, 'onRunnerEnd']); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param \Evenement\EventEmitterInterface $eventEmitter |
61
|
|
|
*/ |
62
|
|
|
public function setEventEmitter(EventEmitterInterface $eventEmitter) |
63
|
|
|
{ |
64
|
|
|
parent::setEventEmitter($eventEmitter); |
65
|
|
|
|
66
|
|
|
array_map(function (ReporterInterface $reporter) use ($eventEmitter) { |
67
|
|
|
$reporter->setEventEmitter($eventEmitter); |
68
|
|
|
}, $this->reporters); |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function onRunnerEnd() |
74
|
|
|
{ |
75
|
|
|
$stdout = $this->getOutput(); |
76
|
|
|
|
77
|
|
|
array_map(function (ReporterInterface $reporter) use ($stdout) { |
78
|
|
|
$output = $reporter->getOutput(); |
79
|
|
|
|
80
|
|
|
if ($output instanceof BufferedOutput && $content = $output->fetch()) { |
81
|
|
|
$stdout->writeln(''); |
82
|
|
|
$stdout->write($content); |
83
|
|
|
} |
84
|
|
|
}, $this->reporters); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|