Completed
Push — master ( 1c5373...ea381d )
by Ross
9s
created

BasicCommandAndBusMappingTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testHandleCommandOnDefaultBus() 0 16 1
A testHandleCommandWithInvalidMiddleware() 0 12 1
A testHandleCommandOnMiddlewareWithDependencies() 0 22 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
    /**
31
     * @expectedException \League\Tactician\Bundle\DependencyInjection\Compiler\UnknownMiddlewareException
32
     */
33
    public function testHandleCommandWithInvalidMiddleware()
34
    {
35
        $this->givenConfig('tactician', <<<'EOF'
36
commandbus:
37
    default:
38
        middleware:
39
            - tactician.middleware.validator
40
            - tactician.middleware.command_handler
41
EOF
42
        );
43
        static::$kernel->boot();
44
    }
45
46
    public function testHandleCommandOnMiddlewareWithDependencies()
47
    {
48
        $this->givenConfig('framework', <<<'EOF'
49
validation:
50
    enabled: true
51
EOF
52
        );
53
        $this->givenConfig('tactician', <<<'EOF'
54
commandbus:
55
    default:
56
        middleware:
57
            - tactician.middleware.validator
58
            - tactician.middleware.command_handler
59
EOF
60
        );
61
        $this->registerService('tactician.test.handler', \League\Tactician\Bundle\Tests\EchoTextHandler::class, [
62
            ['name' => 'tactician.handler', 'command' => 'League\Tactician\Bundle\Tests\EchoText'],
63
        ]);
64
65
        $this->expectOutputString('Hello world');
66
        $this->handleCommand('default', \League\Tactician\Bundle\Tests\EchoText::class, ['Hello world']);
67
    }
68
69
    public function testHandleCommandOnSpecificBus()
70
    {
71
        $this->givenConfig('tactician', <<<'EOF'
72
commandbus:
73
    default:
74
        middleware:
75
            - tactician.middleware.command_handler
76
    other:
77
        middleware:
78
            - tactician.commandbus.other.middleware.command_handler
79
EOF
80
        );
81
        $this->registerService('tactician.test.handler', \League\Tactician\Bundle\Tests\EchoTextHandler::class, [
82
            ['name' => 'tactician.handler', 'command' => 'League\Tactician\Bundle\Tests\EchoText', 'bus' => 'other'],
83
        ]);
84
        $this->expectOutputString('Welcome');
85
        $this->handleCommand('other', \League\Tactician\Bundle\Tests\EchoText::class, ['Welcome']);
86
    }
87
88
    /**
89
     * @expectedException \Exception
90
     * @expectedExceptionMessage Invalid bus id "other". Valid buses are: default
91
     */
92
    public function testHandlerOnUnknownBus()
93
    {
94
        $this->givenConfig('tactician', <<<'EOF'
95
commandbus:
96
    default:
97
        middleware:
98
            - tactician.middleware.command_handler
99
EOF
100
        );
101
        $this->registerService('tactician.test.handler', \League\Tactician\Bundle\Tests\EchoTextHandler::class, [
102
            ['name' => 'tactician.handler', 'command' => 'League\Tactician\Bundle\Tests\EchoText', 'bus' => 'other'],
103
        ]);
104
        static::$kernel->boot();
105
    }
106
107
    /**
108
     * @expectedException \League\Tactician\Exception\MissingHandlerException
109
     */
110
    public function testHandleCommandSpecifiedOnAnotherBus()
111
    {
112
        $this->givenConfig('tactician', <<<'EOF'
113
commandbus:
114
    default:
115
        middleware:
116
            - tactician.middleware.command_handler
117
    other:
118
        middleware:
119
            - tactician.commandbus.other.middleware.command_handler
120
EOF
121
        );
122
        $this->registerService('tactician.test.handler', \League\Tactician\Bundle\Tests\EchoTextHandler::class, [
123
            ['name' => 'tactician.handler', 'command' => 'League\Tactician\Bundle\Tests\EchoText', 'bus' => 'other'],
124
        ]);
125
        $this->handleCommand('default', \League\Tactician\Bundle\Tests\EchoText::class, ['Welcome']);
126
    }
127
}
128