|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace TMV\Laminas\Messenger\Test\Factory\Transport\Sender; |
|
6
|
|
|
|
|
7
|
|
|
use Prophecy\PhpUnit\ProphecyTrait; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Psr\Container\ContainerInterface; |
|
10
|
|
|
use Symfony\Component\Messenger\Envelope; |
|
11
|
|
|
use Symfony\Component\Messenger\Transport\Sender\SendersLocator; |
|
12
|
|
|
use Symfony\Component\Messenger\Transport\TransportInterface; |
|
13
|
|
|
use TMV\Laminas\Messenger\Exception\LogicException; |
|
14
|
|
|
use TMV\Laminas\Messenger\Factory\Transport\Sender\SendersLocatorFactory; |
|
15
|
|
|
use TMV\Laminas\Messenger\Test\Factory\MessageMock; |
|
16
|
|
|
|
|
17
|
|
|
use function iterator_to_array; |
|
18
|
|
|
|
|
19
|
|
|
class SendersLocatorFactoryTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
use ProphecyTrait; |
|
22
|
|
|
|
|
23
|
|
|
public function testFactory(): void |
|
24
|
|
|
{ |
|
25
|
|
|
$container = $this->prophesize(ContainerInterface::class); |
|
26
|
|
|
$container->has('config')->willReturn(true); |
|
27
|
|
|
$container->get('config')->willReturn([ |
|
28
|
|
|
'messenger' => [ |
|
29
|
|
|
'buses' => [ |
|
30
|
|
|
'bus_name' => [ |
|
31
|
|
|
'routes' => [ |
|
32
|
|
|
MessageMock::class => ['transport_name'], |
|
33
|
|
|
], |
|
34
|
|
|
], |
|
35
|
|
|
], |
|
36
|
|
|
'transports' => [ |
|
37
|
|
|
'transport_name' => [], |
|
38
|
|
|
], |
|
39
|
|
|
], |
|
40
|
|
|
]); |
|
41
|
|
|
|
|
42
|
|
|
$transport = $this->prophesize(TransportInterface::class); |
|
43
|
|
|
|
|
44
|
|
|
$container->has('transport_name')->willReturn(true); |
|
45
|
|
|
$container->get('transport_name') |
|
46
|
|
|
->shouldBeCalled() |
|
47
|
|
|
->willReturn($transport->reveal()); |
|
48
|
|
|
|
|
49
|
|
|
$factory = new SendersLocatorFactory('bus_name'); |
|
50
|
|
|
|
|
51
|
|
|
/** @var SendersLocator $service */ |
|
52
|
|
|
$service = $factory($container->reveal()); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertInstanceOf(SendersLocator::class, $service); |
|
55
|
|
|
$senders = iterator_to_array($service->getSenders(new Envelope(new MessageMock()))); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertSame(['transport_name' => $transport->reveal()], $senders); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testFactoryWithInvalidRouteShouldThrowException(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->expectException(LogicException::class); |
|
63
|
|
|
$this->expectExceptionMessage('Invalid Messenger routing configuration: class or interface "foo" not found.'); |
|
64
|
|
|
|
|
65
|
|
|
$container = $this->prophesize(ContainerInterface::class); |
|
66
|
|
|
$container->has('config')->willReturn(true); |
|
67
|
|
|
$container->get('config')->willReturn([ |
|
68
|
|
|
'messenger' => [ |
|
69
|
|
|
'buses' => [ |
|
70
|
|
|
'bus_name' => [ |
|
71
|
|
|
'routes' => [ |
|
72
|
|
|
'foo' => [], |
|
73
|
|
|
], |
|
74
|
|
|
], |
|
75
|
|
|
], |
|
76
|
|
|
], |
|
77
|
|
|
]); |
|
78
|
|
|
|
|
79
|
|
|
$factory = new SendersLocatorFactory('bus_name'); |
|
80
|
|
|
$factory($container->reveal()); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|