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
|
|
|
try { |
50
|
|
|
$dtcQueueExtension->load($configs, $containerBuilder); |
51
|
|
|
if (!$good) { |
52
|
|
|
$this->fail('Bad config should not reach here: '.print_r($configs, true)); |
53
|
|
|
} |
54
|
|
|
} catch (\Exception $exception) { |
55
|
|
|
if ($good) { |
56
|
|
|
self::fail($exception->getMessage()); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
self::assertTrue(true); |
60
|
|
|
|
61
|
|
|
return $containerBuilder; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testRabbitMq() |
65
|
|
|
{ |
66
|
|
|
$configs = ['config' => ['rabbit_mq' => []]]; |
67
|
|
|
$this->tryBadConfigs($configs); |
68
|
|
|
|
69
|
|
|
$configs = ['config' => ['rabbit_mq' => ['host' => 'somehost', 'port' => 1234, 'user' => 'auser', 'password' => 'pass']]]; |
70
|
|
|
$containerBuilder = $this->tryConfigs($configs); |
71
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'host', 'somehost'); |
72
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'port', 1234); |
73
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'user', 'auser'); |
74
|
|
|
$this->arrayTest($containerBuilder, 'dtc_queue.rabbit_mq', 'password', 'pass'); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function arrayTest(ContainerBuilder $containerBuilder, $parameter, $key, $result) |
78
|
|
|
{ |
79
|
|
|
$arr = $containerBuilder->getParameter($parameter); |
80
|
|
|
self::assertArrayHasKey($key, $arr); |
81
|
|
|
self::assertEquals($result, $arr[$key]); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|