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

FailedMessagesRemoveCommandFactoryTest   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\FailedMessagesRemoveCommand;
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\Command\FailedMessagesRemoveCommandFactory;
15
16
class FailedMessagesRemoveCommandFactoryTest 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
                'failure_transport' => 'failed',
28
                'transports' => [],
29
            ],
30
        ]);
31
32
        $receiversLocator = $this->prophesize(ServiceProviderInterface::class);
33
        $failedTransport = $this->prophesize(TransportInterface::class);
34
        $container->get('messenger.receivers_locator')
35
            ->shouldBeCalled()
36
            ->willReturn($receiversLocator->reveal());
37
38
        $factory = new FailedMessagesRemoveCommandFactory();
39
40
        $service = $factory($container->reveal());
41
42
        $this->assertInstanceOf(FailedMessagesRemoveCommand::class, $service);
43
    }
44
45
    public function testFactoryWithNoFailureTransportShouldThrowException(): void
46
    {
47
        $this->expectException(InvalidArgumentException::class);
48
        $this->expectExceptionMessage('Invalid failure_transport name');
49
50
        $container = $this->prophesize(ContainerInterface::class);
51
52
        $container->has('config')->willReturn(true);
53
        $container->get('config')->willReturn([
54
            'messenger' => [
55
                'failure_transport' => null,
56
            ],
57
        ]);
58
59
        $factory = new FailedMessagesRemoveCommandFactory();
60
61
        $factory($container->reveal());
62
    }
63
}
64