1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Paraunit\Configuration\DependencyInjection; |
6
|
|
|
|
7
|
|
|
use Paraunit\Configuration\TempFilenameFactory; |
8
|
|
|
use Paraunit\Parser\DeprecationParser; |
9
|
|
|
use Paraunit\Parser\JSON\AbnormalTerminatedParser; |
10
|
|
|
use Paraunit\Parser\JSON\GenericParser; |
11
|
|
|
use Paraunit\Parser\JSON\LogFetcher; |
12
|
|
|
use Paraunit\Parser\JSON\LogParser; |
13
|
|
|
use Paraunit\Parser\JSON\LogPrinter; |
14
|
|
|
use Paraunit\Parser\JSON\RetryParser; |
15
|
|
|
use Paraunit\Parser\JSON\TestStartParser; |
16
|
|
|
use Paraunit\Parser\JSON\UnknownResultParser; |
17
|
|
|
use Paraunit\TestResult\TestResultFactory; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
19
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
20
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
21
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
22
|
|
|
|
23
|
|
|
class ParserDefinition |
24
|
|
|
{ |
25
|
70 |
|
public function configure(ContainerBuilder $container) |
26
|
|
|
{ |
27
|
70 |
|
$logParser = new Definition(LogParser::class, [ |
28
|
70 |
|
new Reference(LogFetcher::class), |
29
|
70 |
|
new Reference('paraunit.test_result.no_test_executed_container'), |
30
|
70 |
|
new Reference(EventDispatcherInterface::class), |
31
|
70 |
|
new Reference(RetryParser::class), |
32
|
|
|
]); |
33
|
|
|
|
34
|
70 |
|
foreach ($this->defineParsers($container) as $reference) { |
35
|
70 |
|
$logParser->addMethodCall('addParser', [$reference]); |
36
|
|
|
} |
37
|
|
|
|
38
|
70 |
|
$container->setDefinition(RetryParser::class, new Definition(RetryParser::class, [ |
39
|
70 |
|
new Reference('paraunit.test_result.retry_container'), |
40
|
70 |
|
'%paraunit.max_retry_count%', |
41
|
|
|
])); |
42
|
|
|
|
43
|
70 |
|
$container->setDefinition(LogParser::class, $logParser); |
44
|
70 |
|
$container->setDefinition(LogFetcher::class, new Definition(LogFetcher::class, [ |
45
|
70 |
|
new Reference(TempFilenameFactory::class), |
46
|
|
|
])); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param ContainerBuilder $container |
51
|
|
|
* @return Reference[] |
52
|
|
|
* @throws \Symfony\Component\DependencyInjection\Exception\BadMethodCallException |
53
|
|
|
*/ |
54
|
70 |
|
private function defineParsers(ContainerBuilder $container): array |
55
|
|
|
{ |
56
|
70 |
|
$testResultFactory = new Reference(TestResultFactory::class); |
57
|
|
|
$parserDefinitions = [ |
58
|
70 |
|
TestStartParser::class => new Definition(TestStartParser::class), |
59
|
70 |
|
'paraunit.parser.pass_parser' => new Definition(GenericParser::class, [ |
60
|
70 |
|
$testResultFactory, |
61
|
70 |
|
new Reference('paraunit.test_result.pass_container'), |
62
|
70 |
|
LogPrinter::STATUS_PASS, |
63
|
|
|
]), |
64
|
70 |
|
'paraunit.parser.incomplete_parser' => new Definition(GenericParser::class, [ |
65
|
70 |
|
$testResultFactory, |
66
|
70 |
|
new Reference('paraunit.test_result.incomplete_container'), |
67
|
70 |
|
LogPrinter::STATUS_ERROR, |
68
|
70 |
|
LogPrinter::MESSAGE_INCOMPLETE_TEST, |
69
|
|
|
]), |
70
|
70 |
|
'paraunit.parser.skipped_parser' => new Definition(GenericParser::class, [ |
71
|
70 |
|
$testResultFactory, |
72
|
70 |
|
new Reference('paraunit.test_result.skipped_container'), |
73
|
70 |
|
LogPrinter::STATUS_ERROR, |
74
|
70 |
|
LogPrinter::MESSAGE_SKIPPED_TEST, |
75
|
|
|
]), |
76
|
70 |
|
'paraunit.parser.risky_parser' => new Definition(GenericParser::class, [ |
77
|
70 |
|
$testResultFactory, |
78
|
70 |
|
new Reference('paraunit.test_result.risky_container'), |
79
|
70 |
|
LogPrinter::STATUS_ERROR, |
80
|
70 |
|
LogPrinter::MESSAGE_RISKY_TEST, |
81
|
|
|
]), |
82
|
70 |
|
'paraunit.parser.warning_parser' => new Definition(GenericParser::class, [ |
83
|
70 |
|
$testResultFactory, |
84
|
70 |
|
new Reference('paraunit.test_result.warning_container'), |
85
|
70 |
|
LogPrinter::STATUS_WARNING, |
86
|
|
|
]), |
87
|
70 |
|
'paraunit.parser.failure_parser' => new Definition(GenericParser::class, [ |
88
|
70 |
|
$testResultFactory, |
89
|
70 |
|
new Reference('paraunit.test_result.failure_container'), |
90
|
70 |
|
LogPrinter::STATUS_FAIL, |
91
|
|
|
]), |
92
|
70 |
|
'paraunit.parser.error_parser' => new Definition(GenericParser::class, [ |
93
|
70 |
|
$testResultFactory, |
94
|
70 |
|
new Reference('paraunit.test_result.error_container'), |
95
|
70 |
|
LogPrinter::STATUS_ERROR, |
96
|
|
|
]), |
97
|
70 |
|
AbnormalTerminatedParser::class => new Definition(AbnormalTerminatedParser::class, [ |
98
|
70 |
|
$testResultFactory, |
99
|
70 |
|
new Reference('paraunit.test_result.abnormal_terminated_container'), |
100
|
70 |
|
LogFetcher::LOG_ENDING_STATUS, |
101
|
|
|
]), |
102
|
70 |
|
UnknownResultParser::class => new Definition(UnknownResultParser::class, [ |
103
|
70 |
|
$testResultFactory, |
104
|
70 |
|
new Reference('paraunit.test_result.unknown_container'), |
105
|
70 |
|
'', |
106
|
|
|
]), |
107
|
|
|
]; |
108
|
|
|
|
109
|
70 |
|
$parserReferences = []; |
110
|
70 |
|
foreach ($parserDefinitions as $name => $definition) { |
111
|
70 |
|
$container->setDefinition($name, $definition); |
112
|
70 |
|
$parserReferences[] = new Reference($name); |
113
|
|
|
} |
114
|
|
|
|
115
|
70 |
|
$container->setDefinition(DeprecationParser::class, new Definition(DeprecationParser::class, [ |
116
|
70 |
|
new Reference('paraunit.test_result.deprecation_container'), |
117
|
|
|
])); |
118
|
|
|
|
119
|
70 |
|
return $parserReferences; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|