Completed
Push — ezp-30616 ( 9239a0...7bf8e8 )
by
unknown
57:53 queued 37:56
created

SignalSlotPassTest::testProcessNoSignal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
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\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Compiler;
10
11
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\SignalSlotPass;
12
use Symfony\Component\DependencyInjection\ContainerBuilder;
13
use Symfony\Component\DependencyInjection\Definition;
14
use PHPUnit\Framework\TestCase;
15
use Symfony\Component\DependencyInjection\Reference;
16
17
class SignalSlotPassTest extends TestCase
18
{
19
    public function testProcess()
20
    {
21
        $dispatcherDef = new Definition();
22
        $slotDef = new Definition();
23
        $signalIdentifier = 'FooSignal';
24
        $slotDef->addTag('ezpublish.api.slot', array('signal' => $signalIdentifier));
25
26
        $containerBuilder = new ContainerBuilder();
27
        $slotId = 'acme.foo_slot';
28
        $containerBuilder->addDefinitions(
29
            array(
30
                $slotId => $slotDef,
31
                'ezpublish.signalslot.signal_dispatcher' => $dispatcherDef,
32
            )
33
        );
34
35
        $pass = new SignalSlotPass();
36
        $pass->process($containerBuilder);
37
        $this->assertTrue($dispatcherDef->hasMethodCall('attach'));
38
        $calls = $dispatcherDef->getMethodCalls();
39
        list($method, $arguments) = $calls[0];
40
        $this->assertSame('attach', $method);
41
        list($signal, $serviceId) = $arguments;
42
        $this->assertSame($signalIdentifier, $signal);
43
        $this->assertEquals($slotId, new Reference($serviceId));
44
    }
45
46
    /**
47
     * @expectedException \LogicException
48
     */
49
    public function testProcessNoSignal()
50
    {
51
        $slotDef = new Definition();
52
        $slotDef->addTag('ezpublish.api.slot', array());
53
54
        $containerBuilder = new ContainerBuilder();
55
        $containerBuilder->addDefinitions(
56
            array(
57
                'acme.foo_slot' => $slotDef,
58
                'ezpublish.signalslot.signal_dispatcher' => new Definition(),
59
            )
60
        );
61
62
        $pass = new SignalSlotPass();
63
        $pass->process($containerBuilder);
64
    }
65
}
66