1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the SignalSlotPassTest class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Publish\Core\Base\Tests\Container\Compiler\Search; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Base\Container\Compiler\Search\SignalSlotPass; |
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 SignalSlotPassTest extends AbstractCompilerPassTestCase |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
protected function setUp() |
20
|
|
|
{ |
21
|
|
|
parent::setUp(); |
22
|
|
|
$this->setDefinition('ezpublish.signalslot.signal_dispatcher', new Definition()); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Register the compiler pass under test, just like you would do inside a bundle's load() |
27
|
|
|
* method:. |
28
|
|
|
* |
29
|
|
|
* $container->addCompilerPass(new MyCompilerPass()); |
30
|
|
|
*/ |
31
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
32
|
|
|
{ |
33
|
|
|
$container->addCompilerPass(new SignalSlotPass()); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testAttachSignal() |
37
|
|
|
{ |
38
|
|
|
$signal = 'signal_identifier'; |
39
|
|
|
$serviceId = 'service_id'; |
40
|
|
|
$def = new Definition(); |
41
|
|
|
$def->addTag('ezpublish.search.slot', array('signal' => $signal)); |
42
|
|
|
$this->setDefinition($serviceId, $def); |
43
|
|
|
|
44
|
|
|
$this->compile(); |
45
|
|
|
|
46
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
47
|
|
|
'ezpublish.signalslot.signal_dispatcher', |
48
|
|
|
'attach', |
49
|
|
|
array($signal, new Reference($serviceId)) |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @expectedException \LogicException |
55
|
|
|
*/ |
56
|
|
|
public function testAttachSignalNoAlias() |
57
|
|
|
{ |
58
|
|
|
$signal = 'signal_identifier'; |
59
|
|
|
$serviceId = 'service_id'; |
60
|
|
|
$def = new Definition(); |
61
|
|
|
$def->addTag('ezpublish.search.slot'); |
62
|
|
|
$this->setDefinition($serviceId, $def); |
63
|
|
|
|
64
|
|
|
$this->compile(); |
65
|
|
|
|
66
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithMethodCall( |
67
|
|
|
'ezpublish.signalslot.signal_dispatcher', |
68
|
|
|
'attach', |
69
|
|
|
array($signal, new Reference($serviceId)) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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.