1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace League\Tactician\Bundle\Tests\DependencyInjection\Compiler\BusBuilder; |
5
|
|
|
|
6
|
|
|
use League\Tactician\Bundle\DependencyInjection\Compiler\BusBuilder\BusBuilder; |
7
|
|
|
use League\Tactician\Bundle\DependencyInjection\Compiler\BusBuilder\BusBuilders; |
8
|
|
|
use League\Tactician\Bundle\DependencyInjection\DuplicatedCommandBusId; |
9
|
|
|
use League\Tactician\Bundle\DependencyInjection\HandlerMapping\Routing; |
10
|
|
|
use League\Tactician\Bundle\DependencyInjection\InvalidCommandBusId; |
11
|
|
|
|
12
|
|
|
final class BusBuildersTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
public function test_can_iterate_over_builders() |
15
|
|
|
{ |
16
|
|
|
$builders = new BusBuilders( |
17
|
|
|
list($a, $b) = $this->buildersNamed('foo', 'bar'), |
18
|
|
|
'foo' |
19
|
|
|
); |
20
|
|
|
|
21
|
|
|
$this->assertEquals(['foo' => $a, 'bar' => $b], iterator_to_array($builders)); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function test_default_builder_must_be_an_id_that_actually_exists() |
25
|
|
|
{ |
26
|
|
|
$this->expectException(InvalidCommandBusId::class); |
27
|
|
|
|
28
|
|
|
$this->builders(['bus1'], 'some_bus_that_does_not_exist'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function test_two_buses_can_not_have_the_same_id() |
32
|
|
|
{ |
33
|
|
|
$this->expectException(DuplicatedCommandBusId::class); |
34
|
|
|
|
35
|
|
|
$this->builders(['bus1', 'bus1']); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function test_blank_routing_has_ids() |
39
|
|
|
{ |
40
|
|
|
$builders = $this->builders(['bus1', 'bus2']); |
41
|
|
|
|
42
|
|
|
$this->assertEquals(new Routing(['bus1', 'bus2']), $builders->createBlankRouting()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
private function builders($ids, $default = 'bus1'): BusBuilders |
46
|
|
|
{ |
47
|
|
|
return new BusBuilders($this->buildersNamed(...$ids), $default); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function buildersNamed(string ...$ids): array |
51
|
|
|
{ |
52
|
|
|
return array_map( |
53
|
|
|
function (string $id) { |
54
|
|
|
return new BusBuilder($id, 'some.inflector', []); |
55
|
|
|
}, |
56
|
|
|
$ids |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|