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

StopWorkersCommandFactoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 44
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\Cache\CacheItemPoolInterface;
10
use Psr\Container\ContainerInterface;
11
use Symfony\Component\Messenger\Command\StopWorkersCommand;
12
use TMV\Laminas\Messenger\Exception\InvalidArgumentException;
13
use TMV\Laminas\Messenger\Factory\Command\StopWorkersCommandFactory;
14
15
class StopWorkersCommandFactoryTest 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
                'cache_pool_for_restart_signal' => 'messenger.cache_pool_for_restart_signal',
27
            ],
28
        ]);
29
30
        $cachePool = $this->prophesize(CacheItemPoolInterface::class);
31
        $container->get('messenger.cache_pool_for_restart_signal')
32
            ->shouldBeCalled()
33
            ->willReturn($cachePool->reveal());
34
35
        $factory = new StopWorkersCommandFactory();
36
37
        $service = $factory($container->reveal());
38
39
        $this->assertInstanceOf(StopWorkersCommand::class, $service);
40
    }
41
42
    public function testFactoryWithNoCachePoolShouldThrowException(): void
43
    {
44
        $this->expectException(InvalidArgumentException::class);
45
        $this->expectExceptionMessage('Invalid cache_pool_for_restart_signal name');
46
47
        $container = $this->prophesize(ContainerInterface::class);
48
49
        $container->has('config')->willReturn(true);
50
        $container->get('config')->willReturn([
51
            'messenger' => [
52
                'cache_pool_for_restart_signal' => null,
53
            ],
54
        ]);
55
56
        $factory = new StopWorkersCommandFactory();
57
58
        $factory($container->reveal());
59
    }
60
}
61