SimpleCommandBusTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 51
c 0
b 0
f 0
wmc 4
lcom 0
cbo 4
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A it_registers_a_handler() 0 6 1
A it_throws_an_error_on_duplicate_handlers() 0 5 1
A it_lets_a_handler_handle_a_command() 0 9 1
1
<?php
2
3
namespace Tactics\CommandBusBundle\Tests;
4
5
use Tactics\CommandBusBundle\CommandBus\SimpleCommandBus;
6
use Tactics\CommandBusBundle\NamingStrategy\ShortNameStrategy;
7
8
/**
9
 * Class SimpleCommandBusTest
10
 * @package Tactics\CommandBusBundle\Tests
11
 */
12
class SimpleCommandBusTest extends \PHPUnit_Framework_TestCase
13
{
14
    /**
15
     * @inheritDoc
16
     */
17
    public function setUp()
18
    {
19
        $this->commandHandler = $this->getMockBuilder('Tactics\CommandBusBundle\CommandHandler\CommandHandler')
20
            ->setMethods(['handle'])
21
            ->getMock()
22
        ;
23
24
        $this->simpleCommandBus = new SimpleCommandBus(new ShortNameStrategy());
25
    }
26
27
    /**
28
     * @test
29
     * @group command_bus
30
     */
31
    public function it_registers_a_handler()
32
    {
33
        $this->simpleCommandBus->registerHandler($this->commandHandler);
34
35
        $this->assertContains($this->commandHandler, $this->simpleCommandBus->getHandlers());
36
    }
37
38
    /**
39
     * @test
40
     * @group command_bus
41
     * @expectedException \Tactics\CommandBusBundle\Exception\DuplicateHandlerException
42
     */
43
    public function it_throws_an_error_on_duplicate_handlers()
44
    {
45
        $this->simpleCommandBus->registerHandler($this->commandHandler);
46
        $this->simpleCommandBus->registerHandler($this->commandHandler);
47
    }
48
49
    /**
50
     * @test
51
     * @group command_bus
52
     */
53
    public function it_lets_a_handler_handle_a_command()
54
    {
55
        $command = new TestCommand();
56
57
        $this->simpleCommandBus->registerHandler(new TestCommandHandler());
58
        $this->simpleCommandBus->handle($command);
59
60
        $this->assertEquals(2, $command->counter);
61
    }
62
}