MappingPrecedenceTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 57
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 1
A test_typehint_mapping_works_standalone() 0 11 1
A test_FQCN_mapping_works_standalone() 0 11 1
A test_FQCN_mapping_has_precedence_over_typehint_mapping() 0 17 1
1
<?php
2
declare(strict_types=1);
3
4
namespace League\Tactician\Bundle\Tests\Integration;
5
6
use League\Tactician\Bundle\Tests\Fake\FakeCommand;
7
8
/**
9
 * @runTestsInSeparateProcesses
10
 */
11
final class MappingPrecedenceTest extends IntegrationTest
12
{
13
    protected function setUp(): void
14
    {
15
        parent::setUp();
16
17
        $this->givenConfig('tactician', <<<'EOF'
18
commandbus:
19
    default:
20
        middleware:
21
            - tactician.middleware.command_handler
22
EOF
23
        );
24
    }
25
26
    public function test_typehint_mapping_works_standalone()
27
    {
28
        $this->registerService(
29
            'tactician.test.handler',
30
            TypehintedHandler::class,
31
            [['name' => 'tactician.handler', 'typehints' => true]]
32
        );
33
34
        $this->expectOutputString("typehint wins");
35
        $this->handleCommand('default', FakeCommand::class);
36
    }
37
38
    public function test_FQCN_mapping_works_standalone()
39
    {
40
        $this->registerService(
41
            'tactician.test.handler',
42
            PlainHandler::class,
43
            [['name' => 'tactician.handler', 'command' => FakeCommand::class]]
44
        );
45
46
        $this->expectOutputString("plain wins");
47
        $this->handleCommand('default', FakeCommand::class);
48
    }
49
50
    public function test_FQCN_mapping_has_precedence_over_typehint_mapping()
51
    {
52
        $this->registerService(
53
            'tactician.test.typehinted_handler',
54
            TypehintedHandler::class,
55
            [['name' => 'tactician.handler', 'typehints' => true]]
56
        );
57
58
        $this->registerService(
59
            'tactician.test.plain_handler',
60
            PlainHandler::class,
61
            [['name' => 'tactician.handler', 'command' => FakeCommand::class]]
62
        );
63
64
        $this->expectOutputString("plain wins");
65
        $this->handleCommand('default', FakeCommand::class);
66
    }
67
}
68
69
class TypehintedHandler
70
{
71
    public function handle(FakeCommand $command)
0 ignored issues
show
Unused Code introduced by
The parameter $command is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
72
    {
73
        echo 'typehint wins';
74
    }
75
}
76
77
class PlainHandler
78
{
79
    public function handle($someCommand)
0 ignored issues
show
Unused Code introduced by
The parameter $someCommand is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
    {
81
        echo 'plain wins';
82
    }
83
}
84