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