1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tactics\CommandBusBundle\Test\DependencyInjection; |
4
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
5
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
6
|
|
|
use Tactics\CommandBusBundle\DependencyInjection\CommandHandlerPass; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class CommandHandlerPassTest |
10
|
|
|
* @package Tactics\CommandBusBundle\Test\DependencyInjection |
11
|
|
|
*/ |
12
|
|
|
class CommandHandlerPassTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @test |
16
|
|
|
* @group command_bus |
17
|
|
|
*/ |
18
|
|
|
public function returns_null_if_command_bus_service_does_not_exist() |
19
|
|
|
{ |
20
|
|
|
$container = new ContainerBuilder(); |
21
|
|
|
|
22
|
|
|
$this->assertNull($this->process($container)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @test |
27
|
|
|
* @group command_bus |
28
|
|
|
*/ |
29
|
|
|
public function adds_tagged_services_to_command_bus() |
30
|
|
|
{ |
31
|
|
|
$container = new ContainerBuilder(); |
32
|
|
|
|
33
|
|
|
$container |
34
|
|
|
->register('command_bus') |
35
|
|
|
->setClass('Tactics\CommandBusBundle\CommandBus\SimpleCommandBus') |
36
|
|
|
->setArguments([new Definition('Tactics\CommandBusBundle\NamingStrategy\ShortNameStrategy')]) |
37
|
|
|
; |
38
|
|
|
|
39
|
|
|
$container |
40
|
|
|
->register('test_command_handler') |
41
|
|
|
->setClass('Tactics\CommandBusBundle\Tests\TestCommandHandler') |
42
|
|
|
->addTag('command_handler') |
43
|
|
|
; |
44
|
|
|
|
45
|
|
|
$container |
46
|
|
|
->register('not_a_command_handler') |
47
|
|
|
->setClass('Tactics\CommandBusBundle\Tests\TestCommand') |
48
|
|
|
; |
49
|
|
|
|
50
|
|
|
$this->process($container); |
51
|
|
|
|
52
|
|
|
$commandBus = $container->get('command_bus'); |
53
|
|
|
|
54
|
|
|
$this->assertContains($container->get('test_command_handler'), $commandBus->getHandlers()); |
55
|
|
|
$this->assertNotContains($container->get('not_a_command_handler'), $commandBus->getHandlers()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param ContainerBuilder $container |
60
|
|
|
*/ |
61
|
|
|
private function process(ContainerBuilder $container) |
62
|
|
|
{ |
63
|
|
|
$commandHandlerBus = new CommandHandlerPass(); |
64
|
|
|
|
65
|
|
|
return $commandHandlerBus->process($container); |
66
|
|
|
} |
67
|
|
|
} |