|
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
|
|
|
|