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

FailedMessagesShowCommandFactoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 50
rs 10
c 0
b 0
f 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 Symfony\Component\Messenger\Command\FailedMessagesShowCommand;
11
use Symfony\Component\Messenger\Transport\TransportInterface;
12
use TMV\Laminas\Messenger\Exception\InvalidArgumentException;
13
use TMV\Laminas\Messenger\Factory\Command\FailedMessagesShowCommandFactory;
14
15
class FailedMessagesShowCommandFactoryTest extends TestCase
16
{
17
    use ProphecyTrait;
18
19
    public function testFactory(): void
20
    {
21
        $container = $this->prophesize(ContainerInterface::class);
22
23
        $container->has('config')->willReturn(true);
24
        $container->get('config')->willReturn([
25
            'messenger' => [
26
                'failure_transport' => 'failed',
27
                'transports' => [],
28
            ],
29
        ]);
30
31
        $receiversLocator = $this->prophesize(ContainerInterface::class);
32
        $failedTransport = $this->prophesize(TransportInterface::class);
33
        $container->get('messenger.receivers_locator')
34
            ->shouldBeCalled()
35
            ->willReturn($receiversLocator->reveal());
36
37
        $factory = new FailedMessagesShowCommandFactory();
38
39
        $service = $factory($container->reveal());
40
41
        $this->assertInstanceOf(FailedMessagesShowCommand::class, $service);
42
    }
43
44
    public function testFactoryWithNoFailureTransportShouldThrowException(): void
45
    {
46
        $this->expectException(InvalidArgumentException::class);
47
        $this->expectExceptionMessage('Invalid failure_transport name');
48
49
        $container = $this->prophesize(ContainerInterface::class);
50
51
        $container->has('config')->willReturn(true);
52
        $container->get('config')->willReturn([
53
            'messenger' => [
54
                'failure_transport' => null,
55
            ],
56
        ]);
57
58
        $factory = new FailedMessagesShowCommandFactory();
59
60
        $factory($container->reveal());
61
    }
62
}
63