MockMapping::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace League\Tactician\Bundle\Tests\DependencyInjection\HandlerMapping;
5
6
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\CompositeMapping;
7
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\HandlerMapping;
8
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\Routing;
9
use League\Tactician\Bundle\Tests\Fake\FakeCommand;
10
use League\Tactician\Bundle\Tests\Fake\OtherFakeCommand;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
13
final class CompositeMappingTest extends \PHPUnit_Framework_TestCase
14
{
15
    public function test_merging_multiple_mappings()
16
    {
17
        $a = new MockMapping(FakeCommand::class, 'fake.command.handler');
18
        $b = new MockMapping(OtherFakeCommand::class, 'other.fake.command.handler');
19
20
        $finalRouting = (new CompositeMapping($a, $b))->build(
21
            new ContainerBuilder(),
22
            new Routing(['default_bus_id'])
23
        );
24
25
        $this->assertEquals(
26
            [
27
                FakeCommand::class => 'fake.command.handler',
28
                OtherFakeCommand::class => 'other.fake.command.handler'
29
            ],
30
            $finalRouting->commandToServiceMapping('default_bus_id')
31
        );
32
    }
33
}
34
35
class MockMapping implements HandlerMapping
36
{
37
    private $fqcn;
38
    private $serviceId;
39
40
    public function __construct($fqcn, $serviceId)
41
    {
42
        $this->fqcn = $fqcn;
43
        $this->serviceId = $serviceId;
44
    }
45
46
    public function build(ContainerBuilder $container, Routing $routing): Routing
47
    {
48
        $routing->routeToAllBuses($this->fqcn, $this->serviceId);
49
        return $routing;
50
    }
51
}
52