CommandRouterTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 18
dl 0
loc 36
ccs 20
cts 22
cp 0.9091
rs 10
c 1
b 0
f 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testInvalidCommand() 0 9 1
A testUnhandledCommand() 0 9 1
A testHandledCommand() 0 12 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/boot project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Tests\Boot\MessageBus;
10
11
use Daikon\Boot\MessageBus\CommandRouter;
12
use Daikon\EventSourcing\Aggregate\Command\CommandHandler;
13
use Daikon\EventSourcing\Aggregate\Command\CommandInterface;
14
use Daikon\Interop\InvalidArgumentException;
15
use Daikon\Interop\RuntimeException;
16
use Daikon\MessageBus\Envelope;
17
use Daikon\MessageBus\MessageInterface;
18
use PHPUnit\Framework\TestCase;
19
20
final class CommandRouterTest extends TestCase
21
{
22 1
    public function testInvalidCommand(): void
23
    {
24
        /** @var MessageInterface $messageMock */
25 1
        $messageMock = $this->createMock(MessageInterface::class);
26 1
        $envelope = Envelope::wrap($messageMock);
27 1
        $commandRouter = new CommandRouter;
28
29 1
        $this->expectException(InvalidArgumentException::class);
30 1
        $commandRouter->handle($envelope);
31
    }
32
33 1
    public function testUnhandledCommand(): void
34
    {
35
        /** @var MessageInterface $messageMock */
36 1
        $messageMock = $this->createMock(CommandInterface::class);
37 1
        $envelope = Envelope::wrap($messageMock);
38 1
        $commandRouter = new CommandRouter;
39
40 1
        $this->expectException(RuntimeException::class);
41 1
        $commandRouter->handle($envelope);
42
    }
43
44 1
    public function testHandledCommand(): void
45
    {
46
        /** @var MessageInterface $messageMock */
47 1
        $messageMock = $this->createMock(CommandInterface::class);
48 1
        $envelope = Envelope::wrap($messageMock);
49 1
        $handlerMock = $this->createMock(CommandHandler::class);
50 1
        $handlerMock->expects($this->once())->method('handle')->with($envelope);
51
        /** @var CommandHandler $handlerMock */
52 1
        $handler = fn(): CommandHandler => $handlerMock;
53 1
        $commandRouter = new CommandRouter([get_class($messageMock) => $handler]);
54
55 1
        $commandRouter->handle($envelope);
56 1
    }
57
}
58