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) |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
echo 'typehint wins'; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
class PlainHandler |
78
|
|
|
{ |
79
|
|
|
public function handle($someCommand) |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
echo 'plain wins'; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.