Completed
Pull Request — master (#41)
by Ross
03:55
created

BasicCommandAndBusMappingTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testHandleCommandOnDefaultBus() 0 16 1
A testHandleCommandOnSpecificBus() 0 18 1
A testHandlerOnUnknownBus() 0 14 1
A testHandleCommandSpecifiedOnAnotherBus() 0 17 1
1
<?php
2
3
namespace League\Tactician\Bundle\Tests\Integration;
4
5
6
/**
7
 * To ensure cache is isolated from each test.
8
 *
9
 * @runTestsInSeparateProcesses
10
 */
11
class BasicCommandAndBusMappingTest extends IntegrationTest
12
{
13
    public function testHandleCommandOnDefaultBus()
14
    {
15
        $this->givenConfig('tactician', <<<'EOF'
16
commandbus:
17
    default:
18
        middleware:
19
            - tactician.middleware.command_handler
20
EOF
21
        );
22
        $this->registerService('tactician.test.handler', \League\Tactician\Bundle\Tests\EchoTextHandler::class, [
23
            ['name' => 'tactician.handler', 'command' => 'League\Tactician\Bundle\Tests\EchoText'],
24
        ]);
25
26
        $this->expectOutputString('Hello world');
27
        $this->handleCommand('default', \League\Tactician\Bundle\Tests\EchoText::class, ['Hello world']);
28
    }
29
30
    public function testHandleCommandOnSpecificBus()
31
    {
32
        $this->givenConfig('tactician', <<<'EOF'
33
commandbus:
34
    default:
35
        middleware:
36
            - tactician.middleware.command_handler
37
    other:
38
        middleware:
39
            - tactician.commandbus.other.middleware.command_handler
40
EOF
41
        );
42
        $this->registerService('tactician.test.handler', \League\Tactician\Bundle\Tests\EchoTextHandler::class, [
43
            ['name' => 'tactician.handler', 'command' => 'League\Tactician\Bundle\Tests\EchoText', 'bus' => 'other'],
44
        ]);
45
        $this->expectOutputString('Welcome');
46
        $this->handleCommand('other', \League\Tactician\Bundle\Tests\EchoText::class, ['Welcome']);
47
    }
48
49
    /**
50
     * @expectedException \Exception
51
     * @expectedExceptionMessage Invalid bus id "other". Valid buses are: default
52
     */
53
    public function testHandlerOnUnknownBus()
54
    {
55
        $this->givenConfig('tactician', <<<'EOF'
56
commandbus:
57
    default:
58
        middleware:
59
            - tactician.middleware.command_handler
60
EOF
61
        );
62
        $this->registerService('tactician.test.handler', \League\Tactician\Bundle\Tests\EchoTextHandler::class, [
63
            ['name' => 'tactician.handler', 'command' => 'League\Tactician\Bundle\Tests\EchoText', 'bus' => 'other'],
64
        ]);
65
        static::$kernel->boot();
66
    }
67
68
    /**
69
     * @expectedException \League\Tactician\Exception\MissingHandlerException
70
     */
71
    public function testHandleCommandSpecifiedOnAnotherBus()
72
    {
73
        $this->givenConfig('tactician', <<<'EOF'
74
commandbus:
75
    default:
76
        middleware:
77
            - tactician.middleware.command_handler
78
    other:
79
        middleware:
80
            - tactician.commandbus.other.middleware.command_handler
81
EOF
82
        );
83
        $this->registerService('tactician.test.handler', \League\Tactician\Bundle\Tests\EchoTextHandler::class, [
84
            ['name' => 'tactician.handler', 'command' => 'League\Tactician\Bundle\Tests\EchoText', 'bus' => 'other'],
85
        ]);
86
        $this->handleCommand('default', \League\Tactician\Bundle\Tests\EchoText::class, ['Welcome']);
87
    }
88
}
89