Completed
Push — master ( ed304f...e36e8e )
by Matthew
05:35
created

DtcQueueExtensionTest::testBeanstalkExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace Dtc\QueueBundle\Tests\DependencyInjection;
4
5
use Dtc\QueueBundle\DependencyInjection\DtcQueueExtension;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
class DtcQueueExtensionTest extends TestCase
10
{
11
    public function testDtcQueueExtension()
12
    {
13
        $dtcQueueExtension = new DtcQueueExtension();
14
        $configs = [];
15
        $containerBuilder = new ContainerBuilder();
16
        $dtcQueueExtension->load($configs, $containerBuilder);
17
18
        self::assertEquals('dtc_queue', $dtcQueueExtension->getAlias());
19
    }
20
21 View Code Duplication
    public function tryBadConfigs(array $configs)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
22
    {
23
        $dtcQueueExtension = new DtcQueueExtension();
24
        $containerBuilder = new ContainerBuilder();
25
        try {
26
            $dtcQueueExtension->load($configs, $containerBuilder);
27
            self::fail('should not reach here');
28
        } catch (\Exception $exception) {
29
            self::assertTrue(true);
30
        }
31
    }
32
33
    public function testBeanstalkExtension()
34
    {
35
        $configs = ['config' => ['beanstalkd' => ['host' => null]]];
36
        $this->tryBadConfigs($configs);
37
        $configs = ['config' => ['beanstalkd' => ['tube' => null]]];
38
        $this->tryBadConfigs($configs);
39
40
        $configs = ['config' => ['beanstalkd' => ['host' => 'somehost']]];
41
        $containerBuilder = $this->tryGoodConfigs($configs);
42
        self::assertEquals('somehost', $containerBuilder->getParameter('dtc_queue.beanstalkd.host'));
43
44
        $configs = ['config' => ['beanstalkd' => ['host' => 'somehost', 'tube' => 'something']]];
45
        $containerBuilder = $this->tryGoodConfigs($configs);
46
47
        self::assertEquals('something', $containerBuilder->getParameter('dtc_queue.beanstalkd.tube'));
48
        self::assertEquals('somehost', $containerBuilder->getParameter('dtc_queue.beanstalkd.host'));
49
    }
50
51 View Code Duplication
    protected function tryGoodConfigs(array $configs)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
52
    {
53
        $dtcQueueExtension = new DtcQueueExtension();
54
        $containerBuilder = new ContainerBuilder();
55
56
        try {
57
            $dtcQueueExtension->load($configs, $containerBuilder);
58
        } catch (\Exception $exception) {
59
            self::fail($exception->getMessage());
60
        }
61
        self::assertTrue(true);
62
63
        return $containerBuilder;
64
    }
65
66
    public function testRabbitMq()
67
    {
68
        $configs = ['config' => ['rabbit_mq' => []]];
69
        $this->tryBadConfigs($configs);
70
71
        $configs = ['config' => ['rabbit_mq' => ['host' => 'somehost', 'port' => 1234, 'user' => 'auser', 'password' => 'pass']]];
72
        $containerBuilder = $this->tryGoodConfigs($configs);
73
        $this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'host', 'somehost');
74
        $this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'port', 1234);
75
        $this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'user', 'auser');
76
        $this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'password', 'pass');
77
    }
78
79
    public function arrayTest(ContainerBuilder $containerBuilder, $parameter, $key, $result)
80
    {
81
        $arr = $containerBuilder->getParameter($parameter);
82
        self::assertArrayHasKey($key, $arr);
83
        self::assertEquals($result, $arr[$key]);
84
    }
85
}
86