1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Compiler; |
10
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\NotificationRendererPass; |
12
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
14
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
15
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
16
|
|
|
|
17
|
|
View Code Duplication |
class NotificationRendererPassTest extends AbstractCompilerPassTestCase |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
const NOTIFICATION_RENDERER_ID = 'notification.renderer.id'; |
20
|
|
|
const NOTIFICATION_ALIAS = 'example'; |
21
|
|
|
|
22
|
|
|
protected function setUp() |
23
|
|
|
{ |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
$this->setDefinition(NotificationRendererPass::REGISTRY_DEFINITION_ID, new Definition()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
30
|
|
|
{ |
31
|
|
|
$container->addCompilerPass(new NotificationRendererPass()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testAddRenderer() |
35
|
|
|
{ |
36
|
|
|
$definition = new Definition(); |
37
|
|
|
$definition->addTag(NotificationRendererPass::TAG_NAME, [ |
38
|
|
|
'alias' => self::NOTIFICATION_ALIAS, |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
|
$this->setDefinition(self::NOTIFICATION_RENDERER_ID, $definition); |
42
|
|
|
$this->compile(); |
43
|
|
|
|
44
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
45
|
|
|
NotificationRendererPass::REGISTRY_DEFINITION_ID, |
46
|
|
|
'addRenderer', |
47
|
|
|
[self::NOTIFICATION_ALIAS, new Reference(self::NOTIFICATION_RENDERER_ID)] |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @expectedException \LogicException |
53
|
|
|
*/ |
54
|
|
|
public function testAddRendererWithoutAliasThrowsLogicException() |
55
|
|
|
{ |
56
|
|
|
$definition = new Definition(); |
57
|
|
|
$definition->addTag(NotificationRendererPass::TAG_NAME); |
58
|
|
|
|
59
|
|
|
$this->setDefinition(self::NOTIFICATION_RENDERER_ID, $definition); |
60
|
|
|
$this->compile(); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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.