Passed
Push — master ( b2b84f...109e7c )
by Thomas Mauro
03:02
created

ConsumeMessagesCommandFactoryTest::testFactory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 40

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 9.28
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TMV\Laminas\Messenger\Test\Factory\Command;
6
7
use PHPUnit\Framework\TestCase;
8
use Prophecy\PhpUnit\ProphecyTrait;
9
use Psr\Container\ContainerInterface;
10
use Psr\Log\LoggerInterface;
11
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
12
use Symfony\Component\Messenger\Command\ConsumeMessagesCommand;
13
use Symfony\Component\Messenger\RoutableMessageBus;
14
use TMV\Laminas\Messenger\Factory\Command\ConsumeMessagesCommandFactory;
15
16
class ConsumeMessagesCommandFactoryTest extends TestCase
17
{
18
    use ProphecyTrait;
19
20
    public function testFactory(): void
21
    {
22
        $container = $this->prophesize(ContainerInterface::class);
23
24
        $container->has('config')->willReturn(true);
25
        $container->get('config')->willReturn([
26
            'messenger' => [
27
                'event_dispatcher' => 'my.event_dispatcher',
28
                'logger' => 'my.logger',
29
                'transports' => [],
30
            ],
31
        ]);
32
33
        $routableMessageBus = $this->prophesize(RoutableMessageBus::class);
34
        $receiversLocator = $this->prophesize(ContainerInterface::class);
35
        $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
36
        $logger = $this->prophesize(LoggerInterface::class);
37
38
        $container->get('messenger.routable_message_bus')
39
            ->shouldBeCalled()
40
            ->willReturn($routableMessageBus->reveal());
41
42
        $container->get('messenger.receivers_locator')
43
            ->shouldBeCalled()
44
            ->willReturn($receiversLocator->reveal());
45
46
        $container->get('my.event_dispatcher')
47
            ->shouldBeCalled()
48
            ->willReturn($eventDispatcher->reveal());
49
50
        $container->get('my.logger')
51
            ->shouldBeCalled()
52
            ->willReturn($logger->reveal());
53
54
        $factory = new ConsumeMessagesCommandFactory();
55
56
        $service = $factory($container->reveal());
57
58
        $this->assertInstanceOf(ConsumeMessagesCommand::class, $service);
59
    }
60
61
    public function testFactoryWithoutOptionalDependencies(): void
62
    {
63
        $container = $this->prophesize(ContainerInterface::class);
64
65
        $container->has('config')->willReturn(true);
66
        $container->get('config')->willReturn([
67
            'messenger' => [
68
                'event_dispatcher' => null,
69
                'logger' => null,
70
                'transports' => [],
71
            ],
72
        ]);
73
74
        $routableMessageBus = $this->prophesize(RoutableMessageBus::class);
75
        $receiversLocator = $this->prophesize(ContainerInterface::class);
76
        $eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
77
        $logger = $this->prophesize(LoggerInterface::class);
78
79
        $container->get('messenger.routable_message_bus')
80
            ->shouldBeCalled()
81
            ->willReturn($routableMessageBus->reveal());
82
83
        $container->get('messenger.receivers_locator')
84
            ->shouldBeCalled()
85
            ->willReturn($receiversLocator->reveal());
86
87
        $container->get('messenger.event_dispatcher')
88
            ->shouldBeCalled()
89
            ->willReturn($eventDispatcher->reveal());
90
91
        $container->get('messenger.logger')
92
            ->shouldNotBeCalled()
93
            ->willReturn($logger->reveal());
94
95
        $factory = new ConsumeMessagesCommandFactory();
96
97
        $service = $factory($container->reveal());
98
99
        $this->assertInstanceOf(ConsumeMessagesCommand::class, $service);
100
    }
101
}
102