Completed
Push — master ( 11c89b...a1f77e )
by Matthew
03:37
created

RabbitMQCompilerPassTest::testProcess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 54
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 9.6716
c 0
b 0
f 0
cc 1
eloc 45
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Dtc\QueueBundle\Tests\DependencyInjection\Compiler;
4
5
use Dtc\QueueBundle\RabbitMQ\JobManager;
6
use Dtc\QueueBundle\DependencyInjection\Compiler\RabbitMQCompilerPass;
7
use PhpAmqpLib\Connection\AMQPSSLConnection;
8
use PhpAmqpLib\Connection\AMQPStreamConnection;
9
use PHPUnit\Framework\TestCase;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\Definition;
12
13
class RabbitMQCompilerPassTest extends TestCase
14
{
15
    public function testProcess()
16
    {
17
        $container = new ContainerBuilder();
18
19
        $count = count($container->getDefinitions());
20
        $compilerPass = new RabbitMQCompilerPass();
21
        $compilerPass->process($container);
22
        self::assertEquals($count, count($container->getDefinitions()));
23
24
        $rabbitMQOptions = [
25
            'host' => 'somehost',
26
            'port' => 1234,
27
            'user' => 'asdf',
28
            'password' => 'pass',
29
            'vhost' => 'vhoster',
30
            'queue_args' => [],
31
            'exchange_args' => [],
32
        ];
33
        $container = new ContainerBuilder();
34
        $count = count($container->getDefinitions());
35
        $container->setParameter('dtc_queue.rabbit_mq', $rabbitMQOptions);
36
        $definition = new Definition();
37
        $definition->setClass(JobManager::class);
38
        $container->addDefinitions(['dtc_queue.job_manager.rabbit_mq' => $definition]);
39
        $compilerPass = new RabbitMQCompilerPass();
40
        $compilerPass->process($container);
41
42
        self::assertGreaterThan($count, count($container->getDefinitions()));
43
        self::assertTrue($container->hasDefinition('dtc_queue.rabbit_mq'));
44
        self::assertEquals(AMQPStreamConnection::class, $container->getDefinition('dtc_queue.rabbit_mq')->getClass());
45
46
        $rabbitMQOptions = [
47
            'host' => 'somehost',
48
            'port' => 1234,
49
            'user' => 'asdf',
50
            'password' => 'pass',
51
            'vhost' => 'vhoster',
52
            'ssl' => true,
53
            'queue_args' => [],
54
            'exchange_args' => [],
55
        ];
56
        $container = new ContainerBuilder();
57
        $count = count($container->getDefinitions());
58
        $container->setParameter('dtc_queue.rabbit_mq', $rabbitMQOptions);
59
        $definition = new Definition();
60
        $definition->setClass(JobManager::class);
61
        $container->addDefinitions(['dtc_queue.job_manager.rabbit_mq' => $definition]);
62
        $compilerPass = new RabbitMQCompilerPass();
63
        $compilerPass->process($container);
64
65
        self::assertGreaterThan($count, count($container->getDefinitions()));
66
        self::assertTrue($container->hasDefinition('dtc_queue.rabbit_mq'));
67
        self::assertEquals(AMQPSSLConnection::class, $container->getDefinition('dtc_queue.rabbit_mq')->getClass());
68
    }
69
}
70