MockMapping   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 17
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A build() 0 5 1
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