1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Paraunit\Configuration; |
5
|
|
|
|
6
|
|
|
use Paraunit\Printer\DebugPrinter; |
7
|
|
|
use Symfony\Component\Config\FileLocator; |
8
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
12
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
13
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
14
|
|
|
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass; |
15
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Paraunit |
19
|
|
|
* @package Paraunit\Configuration |
20
|
|
|
*/ |
21
|
|
|
class ParallelConfiguration |
22
|
|
|
{ |
23
|
|
|
const TAG_EVENT_SUBSCRIBER = 'paraunit.event_subscriber'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param InputInterface $input |
27
|
|
|
* @param OutputInterface $output |
28
|
|
|
* @return ContainerBuilder |
29
|
|
|
* @throws \Symfony\Component\DependencyInjection\Exception\BadMethodCallException |
30
|
|
|
* @throws \Exception |
31
|
|
|
*/ |
32
|
57 |
|
public function buildContainer(InputInterface $input, OutputInterface $output): ContainerBuilder |
33
|
|
|
{ |
34
|
57 |
|
$containerBuilder = new ContainerBuilder(); |
35
|
|
|
|
36
|
57 |
|
$this->injectOutput($containerBuilder, $output); |
37
|
57 |
|
$this->loadYamlConfiguration($containerBuilder); |
38
|
57 |
|
$this->loadCommandLineOptions($containerBuilder, $input); |
39
|
57 |
|
$this->tagEventSubscribers($containerBuilder); |
40
|
|
|
|
41
|
57 |
|
if ($input->getOption('debug')) { |
42
|
1 |
|
$this->enableDebugMode($containerBuilder); |
43
|
|
|
} |
44
|
|
|
|
45
|
57 |
|
$containerBuilder->compile(); |
46
|
|
|
|
47
|
57 |
|
$this->loadPostCompileSettings($containerBuilder, $input); |
48
|
|
|
|
49
|
57 |
|
return $containerBuilder; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param ContainerBuilder $containerBuilder |
54
|
|
|
* @return YamlFileLoader |
55
|
|
|
* @throws \Exception |
56
|
|
|
*/ |
57
|
57 |
|
protected function loadYamlConfiguration(ContainerBuilder $containerBuilder): YamlFileLoader |
58
|
|
|
{ |
59
|
57 |
|
$loader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__ . '/../Resources/config/')); |
60
|
57 |
|
$loader->load('configuration.yml'); |
61
|
57 |
|
$loader->load('file.yml'); |
62
|
57 |
|
$loader->load('parser.yml'); |
63
|
57 |
|
$loader->load('printer.yml'); |
64
|
57 |
|
$loader->load('process.yml'); |
65
|
57 |
|
$loader->load('runner.yml'); |
66
|
57 |
|
$loader->load('services.yml'); |
67
|
57 |
|
$loader->load('test_result.yml'); |
68
|
57 |
|
$loader->load('test_result_container.yml'); |
69
|
57 |
|
$loader->load('test_result_format.yml'); |
70
|
|
|
|
71
|
57 |
|
return $loader; |
72
|
|
|
} |
73
|
|
|
|
74
|
57 |
|
protected function tagEventSubscribers(ContainerBuilder $container) |
75
|
|
|
{ |
76
|
57 |
|
$container->addCompilerPass(new RegisterListenersPass('event_dispatcher', null, self::TAG_EVENT_SUBSCRIBER)); |
77
|
|
|
|
78
|
57 |
|
foreach ($container->getDefinitions() as $definition) { |
79
|
57 |
|
$reflection = new \ReflectionClass($definition->getClass()); |
80
|
|
|
|
81
|
57 |
|
if ($reflection->implementsInterface(EventSubscriberInterface::class)) { |
82
|
57 |
|
$definition->addTag(self::TAG_EVENT_SUBSCRIBER); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
57 |
|
protected function loadCommandLineOptions(ContainerBuilder $containerBuilder, InputInterface $input) |
88
|
|
|
{ |
89
|
57 |
|
$containerBuilder->setParameter('paraunit.max_process_count', $input->getOption('parallel')); |
90
|
57 |
|
$containerBuilder->setParameter('paraunit.phpunit_config_filename', $input->getOption('configuration') ?? '.'); |
91
|
57 |
|
$containerBuilder->setParameter('paraunit.testsuite', $input->getOption('testsuite')); |
92
|
57 |
|
$containerBuilder->setParameter('paraunit.string_filter', $input->getArgument('stringFilter')); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
protected function loadPostCompileSettings(ContainerBuilder $container, InputInterface $input) |
96
|
|
|
{ |
97
|
|
|
} |
98
|
|
|
|
99
|
57 |
|
private function injectOutput(ContainerBuilder $containerBuilder, OutputInterface $output) |
100
|
|
|
{ |
101
|
57 |
|
$containerBuilder->register('output') |
102
|
57 |
|
->setSynthetic(true); |
103
|
|
|
|
104
|
57 |
|
$containerBuilder->set('output', $output); |
105
|
|
|
} |
106
|
|
|
|
107
|
1 |
|
private function enableDebugMode(ContainerBuilder $containerBuilder) |
108
|
|
|
{ |
109
|
1 |
|
$definition = new Definition(DebugPrinter::class, [new Reference('output')]); |
110
|
1 |
|
$definition->addTag(self::TAG_EVENT_SUBSCRIBER); |
111
|
|
|
|
112
|
1 |
|
$containerBuilder->setDefinition('paraunit.printer.debug_printer', $definition); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|