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

ValidatorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanBootKernelWhenOptionalComponentMiddlewareIsEnabled() 0 17 1
A testCanNotBootKernelWhenOptionalComponentMiddlewareIsDisabled() 0 19 1
A testHandleCommandOnMiddlewareWithDependencies() 0 22 1
1
<?php
2
declare(strict_types=1);
3
4
namespace League\Tactician\Bundle\Tests\Integration;
5
6
use League\Tactician\Bundle\DependencyInjection\Compiler\UnknownMiddleware;
7
8
/**
9
 * @runTestsInSeparateProcesses
10
 */
11
final class ValidatorTest extends IntegrationTest
12
{
13
    public function testCanBootKernelWhenOptionalComponentMiddlewareIsEnabled()
14
    {
15
        $this->givenConfig('framework', <<<'EOF'
16
validation:
17
    enabled: true
18
EOF
19
        );
20
21
        $this->givenConfig('tactician', <<<'EOF'
22
commandbus:
23
    default:
24
        middleware:
25
            - tactician.middleware.validator
26
EOF
27
        );
28
        static::$kernel->boot();
29
    }
30
31
    public function testCanNotBootKernelWhenOptionalComponentMiddlewareIsDisabled()
32
    {
33
        $this->expectException(UnknownMiddleware::class);
34
35
        $this->givenConfig('framework', <<<'EOF'
36
validation:
37
    enabled: false
38
EOF
39
        );
40
41
        $this->givenConfig('tactician', <<<'EOF'
42
commandbus:
43
    default:
44
        middleware:
45
            - tactician.middleware.validator
46
EOF
47
        );
48
        static::$kernel->boot();
49
    }
50
51
    public function testHandleCommandOnMiddlewareWithDependencies()
52
    {
53
        $this->givenConfig('framework', <<<'EOF'
54
validation:
55
    enabled: true
56
EOF
57
        );
58
        $this->givenConfig('tactician', <<<'EOF'
59
commandbus:
60
    default:
61
        middleware:
62
            - tactician.middleware.validator
63
            - tactician.middleware.command_handler
64
EOF
65
        );
66
        $this->registerService('tactician.test.handler', \League\Tactician\Bundle\Tests\EchoTextHandler::class, [
67
            ['name' => 'tactician.handler', 'command' => 'League\Tactician\Bundle\Tests\EchoText'],
68
        ]);
69
70
        $this->expectOutputString('Hello world');
71
        $this->handleCommand('default', \League\Tactician\Bundle\Tests\EchoText::class, ['Hello world']);
72
    }
73
}