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
|
|
|
protected function tryBadConfigs(array $configs) |
22
|
|
|
{ |
23
|
|
|
return $this->tryConfigs($configs, false); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testBeanstalkExtension() |
27
|
|
|
{ |
28
|
|
|
$configs = ['config' => ['beanstalkd' => ['host' => null]]]; |
29
|
|
|
$this->tryBadConfigs($configs); |
30
|
|
|
$configs = ['config' => ['beanstalkd' => ['tube' => null]]]; |
31
|
|
|
$this->tryBadConfigs($configs); |
32
|
|
|
|
33
|
|
|
$configs = ['config' => ['beanstalkd' => ['host' => 'somehost']]]; |
34
|
|
|
$containerBuilder = $this->tryConfigs($configs); |
35
|
|
|
self::assertEquals('somehost', $containerBuilder->getParameter('dtc_queue.beanstalkd.host')); |
36
|
|
|
|
37
|
|
|
$configs = ['config' => ['beanstalkd' => ['host' => 'somehost', 'tube' => 'something']]]; |
38
|
|
|
$containerBuilder = $this->tryConfigs($configs); |
39
|
|
|
|
40
|
|
|
self::assertEquals('something', $containerBuilder->getParameter('dtc_queue.beanstalkd.tube')); |
41
|
|
|
self::assertEquals('somehost', $containerBuilder->getParameter('dtc_queue.beanstalkd.host')); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function tryConfigs(array $configs, $good = true) |
45
|
|
|
{ |
46
|
|
|
$dtcQueueExtension = new DtcQueueExtension(); |
47
|
|
|
$containerBuilder = new ContainerBuilder(); |
48
|
|
|
|
49
|
|
|
$failed = false; |
50
|
|
|
try { |
51
|
|
|
$dtcQueueExtension->load($configs, $containerBuilder); |
52
|
|
|
if (!$good) { |
53
|
|
|
$failed = true; |
54
|
|
|
} |
55
|
|
|
} catch (\Exception $exception) { |
56
|
|
|
if ($good) { |
57
|
|
|
self::fail($exception->getMessage()); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
self::assertFalse($failed); |
61
|
|
|
|
62
|
|
|
return $containerBuilder; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testRabbitMq() |
66
|
|
|
{ |
67
|
|
|
$configs = ['config' => ['rabbit_mq' => []]]; |
68
|
|
|
$this->tryBadConfigs($configs); |
69
|
|
|
|
70
|
|
|
$configs = ['config' => ['rabbit_mq' => ['host' => 'somehost', 'port' => 1234, 'user' => 'auser', 'password' => 'pass']]]; |
71
|
|
|
$containerBuilder = $this->tryConfigs($configs); |
72
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'host', 'somehost'); |
73
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'port', 1234); |
74
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'user', 'auser'); |
75
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'password', 'pass'); |
76
|
|
|
|
77
|
|
|
$configs = ['config' => ['rabbit_mq' => ['host' => 'somehost', 'port' => 1234, 'user' => 'auser', 'password' => 'pass', 'options' => ['insist' => true]]]]; |
78
|
|
|
$containerBuilder = $this->tryConfigs($configs); |
79
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'options', ['insist' => true]); |
80
|
|
|
|
81
|
|
|
$configs = ['config' => ['rabbit_mq' => ['host' => 'somehost', 'port' => 1234, 'user' => 'auser', 'ssl_options' => ['a' => true], 'password' => 'pass']]]; |
82
|
|
|
$this->tryBadConfigs($configs); |
83
|
|
|
|
84
|
|
|
$configs = ['config' => ['rabbit_mq' => ['host' => 'somehost', 'port' => 1234, 'user' => 'auser', 'ssl' => true, 'ssl_options' => ['a' => true], 'password' => 'pass']]]; |
85
|
|
|
$containerBuilder = $this->tryConfigs($configs); |
86
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'ssl_options', ['a' => true]); |
87
|
|
|
$rabbitMq = $containerBuilder->getParameter('dtc_queue.rabbit_mq'); |
88
|
|
|
self::assertFalse(isset($rabbitMq['options'])); |
89
|
|
|
|
90
|
|
|
$configs = ['config' => ['rabbit_mq' => ['host' => 'somehost', 'port' => 1234, 'user' => 'auser', 'ssl' => true, 'ssl_options' => ['a' => ['something']], 'password' => 'pass']]]; |
91
|
|
|
$this->tryBadConfigs($configs); |
92
|
|
|
|
93
|
|
|
$configs = ['config' => ['rabbit_mq' => ['host' => 'somehost', 'port' => 1234, 'user' => 'auser', 'ssl' => true, 'ssl_options' => ['peer_fingerprint' => ['something' => 'else']], 'password' => 'pass']]]; |
94
|
|
|
$containerBuilder = $this->tryConfigs($configs); |
95
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'ssl_options', ['peer_fingerprint' => ['something' => 'else']]); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function arrayTest(ContainerBuilder $containerBuilder, $parameter, $key, $result) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$arr = $containerBuilder->getParameter($parameter); |
101
|
|
|
self::assertArrayHasKey($key, $arr); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.