|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace TMV\Laminas\Messenger\Test\Factory\Transport\Receiver; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Prophecy\PhpUnit\ProphecyTrait; |
|
9
|
|
|
use Psr\Container\ContainerInterface; |
|
10
|
|
|
use Symfony\Component\Messenger\Transport\Receiver\ReceiverInterface; |
|
11
|
|
|
use Symfony\Component\Messenger\Transport\TransportInterface; |
|
12
|
|
|
use Symfony\Contracts\Service\ServiceProviderInterface; |
|
13
|
|
|
use TMV\Laminas\Messenger\Exception\InvalidArgumentException; |
|
14
|
|
|
use TMV\Laminas\Messenger\Factory\Transport\Receiver\ReceiversLocatorFactory; |
|
15
|
|
|
|
|
16
|
|
|
class ReceiversLocatorFactoryTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
use ProphecyTrait; |
|
19
|
|
|
|
|
20
|
|
|
public function testFactory(): void |
|
21
|
|
|
{ |
|
22
|
|
|
$container = $this->prophesize(ContainerInterface::class); |
|
23
|
|
|
$container->has('config')->willReturn(true); |
|
24
|
|
|
$container->get('config')->willReturn([ |
|
25
|
|
|
'messenger' => [ |
|
26
|
|
|
'transports' => [ |
|
27
|
|
|
'foo' => [], |
|
28
|
|
|
], |
|
29
|
|
|
'receivers' => [ |
|
30
|
|
|
'bar' => 'bar_receiver', |
|
31
|
|
|
], |
|
32
|
|
|
], |
|
33
|
|
|
]); |
|
34
|
|
|
|
|
35
|
|
|
$fooTransport = $this->prophesize(TransportInterface::class); |
|
36
|
|
|
$barReceiver = $this->prophesize(ReceiverInterface::class); |
|
37
|
|
|
|
|
38
|
|
|
$container->get('foo') |
|
39
|
|
|
->shouldBeCalled() |
|
40
|
|
|
->willReturn($fooTransport->reveal()); |
|
41
|
|
|
|
|
42
|
|
|
$container->get('bar_receiver') |
|
43
|
|
|
->shouldBeCalled() |
|
44
|
|
|
->willReturn($barReceiver->reveal()); |
|
45
|
|
|
|
|
46
|
|
|
$factory = new ReceiversLocatorFactory(); |
|
47
|
|
|
$service = $factory($container->reveal()); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertInstanceOf(ServiceProviderInterface::class, $service); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertSame($fooTransport->reveal(), $service->get('foo')); |
|
52
|
|
|
$this->assertSame($barReceiver->reveal(), $service->get('bar')); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testFactoryWithSameTransportAndReceiverNameShouldThrowException(): void |
|
56
|
|
|
{ |
|
57
|
|
|
$this->expectException(InvalidArgumentException::class); |
|
58
|
|
|
$this->expectExceptionMessage('A receiver named "foo" already exists as a transport name'); |
|
59
|
|
|
|
|
60
|
|
|
$container = $this->prophesize(ContainerInterface::class); |
|
61
|
|
|
$container->has('config')->willReturn(true); |
|
62
|
|
|
$container->get('config')->willReturn([ |
|
63
|
|
|
'messenger' => [ |
|
64
|
|
|
'transports' => [ |
|
65
|
|
|
'foo' => [], |
|
66
|
|
|
], |
|
67
|
|
|
'receivers' => [ |
|
68
|
|
|
'foo' => 'bar_receiver', |
|
69
|
|
|
], |
|
70
|
|
|
], |
|
71
|
|
|
]); |
|
72
|
|
|
|
|
73
|
|
|
$factory = new ReceiversLocatorFactory(); |
|
74
|
|
|
$service = $factory($container->reveal()); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|