|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\Tests\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use Dtc\QueueBundle\DependencyInjection\DtcQueueExtension; |
|
6
|
|
|
use Dtc\QueueBundle\Redis\JobManager; |
|
7
|
|
|
use Dtc\QueueBundle\DependencyInjection\Compiler\RedisCompilerPass; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
10
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
11
|
|
|
|
|
12
|
|
|
class RedisCompilerPassTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testProcess() |
|
15
|
|
|
{ |
|
16
|
|
|
$container = new ContainerBuilder(); |
|
17
|
|
|
|
|
18
|
|
|
$count = count($container->getDefinitions()); |
|
19
|
|
|
$compilerPass = new RedisCompilerPass(); |
|
20
|
|
|
$compilerPass->process($container); |
|
21
|
|
|
self::assertEquals($count, count($container->getDefinitions())); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testSncRedis() |
|
25
|
|
|
{ |
|
26
|
|
|
$container = new ContainerBuilder(); |
|
27
|
|
|
$count = count($container->getDefinitions()); |
|
28
|
|
|
$definition = new Definition(); |
|
29
|
|
|
$definition->setClass(JobManager::class); |
|
30
|
|
|
$container->addDefinitions(['dtc_queue.job_manager.redis' => $definition]); |
|
31
|
|
|
$container->setParameter('dtc_queue.redis.snc_redis.type', 'predis'); |
|
32
|
|
|
$container->setParameter('dtc_queue.redis.snc_redis.alias', 'default'); |
|
33
|
|
|
$compilerPass = new RedisCompilerPass(); |
|
34
|
|
|
$compilerPass->process($container); |
|
35
|
|
|
|
|
36
|
|
|
self::assertGreaterThan($count, count($container->getDefinitions())); |
|
37
|
|
|
self::assertTrue($container->hasDefinition('dtc_queue.predis')); |
|
38
|
|
|
|
|
39
|
|
|
$definition = $container->getDefinition('dtc_queue.job_manager.redis'); |
|
40
|
|
|
self::assertNotEmpty($definition->getMethodCalls()); |
|
41
|
|
|
self::assertCount(1, $definition->getMethodCalls()); |
|
42
|
|
|
|
|
43
|
|
|
$container = new ContainerBuilder(); |
|
44
|
|
|
$count = count($container->getDefinitions()); |
|
45
|
|
|
$definition = new Definition(); |
|
46
|
|
|
$definition->setClass(JobManager::class); |
|
47
|
|
|
$container->addDefinitions(['dtc_queue.job_manager.redis' => $definition]); |
|
48
|
|
|
$container->setParameter('dtc_queue.redis.snc_redis.type', 'phpredis'); |
|
49
|
|
|
$container->setParameter('dtc_queue.redis.snc_redis.alias', 'default'); |
|
50
|
|
|
$compilerPass = new RedisCompilerPass(); |
|
51
|
|
|
$compilerPass->process($container); |
|
52
|
|
|
|
|
53
|
|
|
self::assertGreaterThan($count, count($container->getDefinitions())); |
|
54
|
|
|
self::assertTrue($container->hasDefinition('dtc_queue.phpredis')); |
|
55
|
|
|
|
|
56
|
|
|
$definition = $container->getDefinition('dtc_queue.job_manager.redis'); |
|
57
|
|
|
self::assertNotEmpty($definition->getMethodCalls()); |
|
58
|
|
|
self::assertCount(1, $definition->getMethodCalls()); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testPredis() |
|
62
|
|
|
{ |
|
63
|
|
|
$container = new ContainerBuilder(); |
|
64
|
|
|
$count = count($container->getDefinitions()); |
|
65
|
|
|
$definition = new Definition(); |
|
66
|
|
|
$definition->setClass(JobManager::class); |
|
67
|
|
|
$container->addDefinitions(['dtc_queue.job_manager.redis' => $definition]); |
|
68
|
|
|
$container->setParameter('dtc_queue.redis.predis.dsn', 'redis://localhost'); |
|
69
|
|
|
$compilerPass = new RedisCompilerPass(); |
|
70
|
|
|
$compilerPass->process($container); |
|
71
|
|
|
|
|
72
|
|
|
self::assertGreaterThan($count, count($container->getDefinitions())); |
|
73
|
|
|
self::assertTrue($container->hasDefinition('dtc_queue.predis')); |
|
74
|
|
|
|
|
75
|
|
|
$definition = $container->getDefinition('dtc_queue.job_manager.redis'); |
|
76
|
|
|
self::assertNotEmpty($definition->getMethodCalls()); |
|
77
|
|
|
self::assertCount(1, $definition->getMethodCalls()); |
|
78
|
|
|
|
|
79
|
|
|
$container = new ContainerBuilder(); |
|
80
|
|
|
$count = count($container->getDefinitions()); |
|
81
|
|
|
$definition = new Definition(); |
|
82
|
|
|
$definition->setClass(JobManager::class); |
|
83
|
|
|
$container->addDefinitions(['dtc_queue.job_manager.redis' => $definition]); |
|
84
|
|
|
$container->setParameter('dtc_queue.redis.predis.connection_parameters', ['host' => 'localhost', 'port' => 6379]); |
|
85
|
|
|
$compilerPass = new RedisCompilerPass(); |
|
86
|
|
|
$compilerPass->process($container); |
|
87
|
|
|
|
|
88
|
|
|
self::assertGreaterThan($count, count($container->getDefinitions())); |
|
89
|
|
|
self::assertTrue($container->hasDefinition('dtc_queue.predis')); |
|
90
|
|
|
|
|
91
|
|
|
$definition = $container->getDefinition('dtc_queue.job_manager.redis'); |
|
92
|
|
|
self::assertNotEmpty($definition->getMethodCalls()); |
|
93
|
|
|
self::assertCount(1, $definition->getMethodCalls()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testPhpRedis() |
|
97
|
|
|
{ |
|
98
|
|
|
$container = new ContainerBuilder(); |
|
99
|
|
|
$count = count($container->getDefinitions()); |
|
100
|
|
|
$dtcQueueExtension = new DtcQueueExtension(); |
|
101
|
|
|
$configs = ['config' => ['redis' => ['phpredis' => ['host' => 'localhost']]]]; |
|
102
|
|
|
$dtcQueueExtension->load($configs, $container); |
|
103
|
|
|
|
|
104
|
|
|
$definition = new Definition(); |
|
105
|
|
|
$definition->setClass(JobManager::class); |
|
106
|
|
|
$container->addDefinitions(['dtc_queue.job_manager.redis' => $definition]); |
|
107
|
|
|
$compilerPass = new RedisCompilerPass(); |
|
108
|
|
|
$compilerPass->process($container); |
|
109
|
|
|
|
|
110
|
|
|
self::assertGreaterThan($count, count($container->getDefinitions())); |
|
111
|
|
|
self::assertTrue($container->hasDefinition('dtc_queue.phpredis')); |
|
112
|
|
|
|
|
113
|
|
|
$definition = $container->getDefinition('dtc_queue.job_manager.redis'); |
|
114
|
|
|
self::assertNotEmpty($definition->getMethodCalls()); |
|
115
|
|
|
self::assertCount(1, $definition->getMethodCalls()); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|