1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Tests\DependencyInjection\Compiler; |
4
|
|
|
|
5
|
|
|
use Cmobi\RabbitmqBundle\Connection\ConnectionManager; |
6
|
|
|
use Cmobi\RabbitmqBundle\DependencyInjection\CmobiRabbitmqExtension; |
7
|
|
|
use Cmobi\RabbitmqBundle\DependencyInjection\Compiler\WorkerPass; |
8
|
|
|
use Cmobi\RabbitmqBundle\Queue\BaseQueueService; |
9
|
|
|
use Cmobi\RabbitmqBundle\Tests\BaseTestCase; |
10
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
11
|
|
|
|
12
|
|
View Code Duplication |
class WorkerPassTest extends BaseTestCase |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
public function testProcess() |
15
|
|
|
{ |
16
|
|
|
$container = new ContainerBuilder(); |
17
|
|
|
$this->declareServiceMock($container); |
18
|
|
|
$container->register('cmobi_rabbitmq.message.handler', BaseQueueService::class) |
19
|
|
|
->setPublic(false); |
20
|
|
|
$container->register('cmobi_rabbitmq.connection.manager', ConnectionManager::class) |
21
|
|
|
->setPublic(false); |
22
|
|
|
|
23
|
|
|
$this->process($container); |
24
|
|
|
|
25
|
|
|
$this->assertTrue($container->hasDefinition('cmobi_rabbitmq.worker.test')); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
private function declareServiceMock(ContainerBuilder $container) |
29
|
|
|
{ |
30
|
|
|
$container->registerExtension(new CmobiRabbitmqExtension()); |
31
|
|
|
$container->register('cmobi_rabbitmq.worker.test') |
32
|
|
|
->setPublic(false); |
33
|
|
|
$container->register('cmobi_rabbitmq.connection.default') |
34
|
|
|
->setPublic(false); |
35
|
|
|
$container->register('cmobi_rabbitmq.logger') |
36
|
|
|
->setPublic(false); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function process(ContainerBuilder $container) |
40
|
|
|
{ |
41
|
|
|
$workerPass = new WorkerPass( |
42
|
|
|
'test', |
43
|
|
|
'cmobi_rabbitmq.connection.default', |
44
|
|
|
'cmobi_rabbitmq.message.handler', |
45
|
|
|
1, |
46
|
|
|
[] |
47
|
|
|
); |
48
|
|
|
$workerPass->process($container); |
49
|
|
|
} |
50
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.