1 | <?php |
||
18 | class Runner implements EventSubscriberInterface |
||
19 | { |
||
20 | /** @var ProcessFactoryInterface */ |
||
21 | private $processFactory; |
||
22 | |||
23 | /** @var EventDispatcherInterface */ |
||
24 | private $eventDispatcher; |
||
25 | |||
26 | /** @var Filter */ |
||
27 | private $filter; |
||
28 | |||
29 | /** @var PipelineCollection */ |
||
30 | private $pipelineCollection; |
||
31 | |||
32 | /** @var \SplQueue */ |
||
33 | private $queuedProcesses; |
||
34 | |||
35 | /** @var int */ |
||
36 | private $exitCode; |
||
37 | |||
38 | /** |
||
39 | * @param EventDispatcherInterface $eventDispatcher |
||
40 | * @param ProcessFactoryInterface $processFactory |
||
41 | * @param Filter $filter |
||
42 | * @param PipelineCollection $pipelineCollection |
||
43 | */ |
||
44 | 39 | public function __construct( |
|
57 | |||
58 | 64 | public static function getSubscribedEvents(): array |
|
59 | { |
||
60 | return [ |
||
61 | 64 | ProcessEvent::PROCESS_TERMINATED => 'pushToPipeline', |
|
62 | 64 | ProcessEvent::PROCESS_TO_BE_RETRIED => 'onProcessToBeRetried', |
|
63 | 64 | ProcessEvent::PROCESS_PARSING_COMPLETED => 'onProcessParsingCompleted', |
|
64 | ]; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return int The final exit code: 0 if no failures, 10 otherwise |
||
69 | */ |
||
70 | 21 | public function run(): int |
|
88 | |||
89 | /** |
||
90 | * @param ProcessEvent $processEvent |
||
91 | */ |
||
92 | 31 | public function onProcessParsingCompleted(ProcessEvent $processEvent) |
|
93 | { |
||
94 | 31 | if ($processEvent->getProcess()->getExitCode() !== 0) { |
|
95 | 14 | $this->exitCode = 10; |
|
96 | } |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param ProcessEvent $processEvent |
||
101 | */ |
||
102 | 7 | public function onProcessToBeRetried(ProcessEvent $processEvent) |
|
103 | { |
||
104 | 7 | $this->queuedProcesses->enqueue($processEvent->getProcess()); |
|
105 | } |
||
106 | |||
107 | 21 | private function createProcessQueue() |
|
108 | { |
||
109 | 21 | foreach ($this->filter->filterTestFiles() as $file) { |
|
110 | 20 | $this->queuedProcesses->enqueue( |
|
111 | 20 | $this->processFactory->create($file) |
|
112 | ); |
||
113 | } |
||
114 | } |
||
115 | |||
116 | 21 | public function pushToPipeline() |
|
122 | } |
||
123 |