MappingPrecedenceTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
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