1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Liip\MonitorBundle\Tests\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Liip\MonitorBundle\DependencyInjection\Compiler\AdditionalReporterCompilerPass; |
6
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
7
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
8
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @author Kevin Bond <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class AdditionalReporterCompilerPassTest extends AbstractCompilerPassTestCase |
15
|
|
|
{ |
16
|
|
View Code Duplication |
public function testProcessWithAlias() |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
$runner = new Definition(); |
19
|
|
|
$this->setDefinition('liip_monitor.runner_default', $runner); |
20
|
|
|
$this->setParameter('liip_monitor.runners', ['liip_monitor.runner_default']); |
21
|
|
|
|
22
|
|
|
$reporter = new Definition(); |
23
|
|
|
$reporter->addTag('liip_monitor.additional_reporter', ['alias' => 'foo']); |
24
|
|
|
$this->setDefinition('foo_reporter', $reporter); |
25
|
|
|
|
26
|
|
|
$this->compile(); |
27
|
|
|
|
28
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
29
|
|
|
'liip_monitor.runner_default', |
30
|
|
|
'addAdditionalReporter', |
31
|
|
|
[ |
32
|
|
|
'foo', |
33
|
|
|
new Reference('foo_reporter'), |
34
|
|
|
] |
35
|
|
|
); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public function testProcessWithoutAlias() |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$runner = new Definition(); |
41
|
|
|
$this->setDefinition('liip_monitor.runner_default', $runner); |
42
|
|
|
$this->setParameter('liip_monitor.runners', ['liip_monitor.runner_default']); |
43
|
|
|
|
44
|
|
|
$reporter = new Definition(); |
45
|
|
|
$reporter->addTag('liip_monitor.additional_reporter'); |
46
|
|
|
$this->setDefinition('foo_reporter', $reporter); |
47
|
|
|
|
48
|
|
|
$this->compile(); |
49
|
|
|
|
50
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
51
|
|
|
'liip_monitor.runner_default', |
52
|
|
|
'addAdditionalReporter', |
53
|
|
|
[ |
54
|
|
|
'foo_reporter', |
55
|
|
|
new Reference('foo_reporter'), |
56
|
|
|
] |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function registerCompilerPass(ContainerBuilder $container): void |
61
|
|
|
{ |
62
|
|
|
$container->addCompilerPass(new AdditionalReporterCompilerPass()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.