Skip to content

Commit 6efe0fd

Browse files
committed
Modified fabric command, completed unit test
1 parent 9136100 commit 6efe0fd

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

Command/SetupFabricCommand.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
2828

2929
$partsHolder = $this->getContainer()->get('old_sound_rabbit_mq.parts_holder');
3030

31-
foreach ($partsHolder->getParts('old_sound_rabbit_mq.base_amqp') as $baseAmqp) {
32-
$baseAmqp->setupFabric();
31+
foreach (array('base_amqp', 'binding') as $key) {
32+
foreach ($partsHolder->getParts('old_sound_rabbit_mq.' . $key) as $baseAmqp) {
33+
$baseAmqp->setupFabric();
34+
}
3335
}
36+
3437
}
3538
}

DependencyInjection/OldSoundRabbitMqExtension.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,12 @@ protected function loadBindings()
106106
ksort($binding);
107107
$definition = new Definition($binding['class']);
108108
$definition->addTag('old_sound_rabbit_mq.binding');
109-
$definition->addMethodCall('setExchange', array($binding['exchange']));
109+
$definition->addMethodCall('setArguments', array($binding['arguments']));
110110
$definition->addMethodCall('setDestination', array($binding['destination']));
111-
$definition->addMethodCall('setRoutingKey', array($binding['routing_key']));
112-
$definition->addMethodCall('isNowait', array($binding['nowait']));
113111
$definition->addMethodCall('setDestinationIsExchange', array($binding['destination_is_exchange']));
112+
$definition->addMethodCall('setExchange', array($binding['exchange']));
113+
$definition->addMethodCall('isNowait', array($binding['nowait']));
114+
$definition->addMethodCall('setRoutingKey', array($binding['routing_key']));
114115
$this->injectConnection($definition, $binding['connection']);
115116
$key = md5(json_encode($binding));
116117
if ($this->collectorEnabled) {

Tests/DependencyInjection/OldSoundRabbitMqExtensionTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace OldSound\RabbitMqBundle\Tests\DependencyInjection;
44

55
use Symfony\Component\DependencyInjection\ContainerBuilder;
6+
use Symfony\Component\DependencyInjection\Definition;
67
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
78
use Symfony\Component\Config\FileLocator;
89
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
@@ -130,6 +131,9 @@ public function testFooBinding()
130131
$key = md5(json_encode($binding));
131132
$name = sprintf('old_sound_rabbit_mq.%s_binding', $key);
132133
$this->assertTrue($container->has($name));
134+
$definition = $container->getDefinition($name);
135+
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default');
136+
$this->assertBindingMethodCalls($definition, $binding);
133137
}
134138

135139
public function testMooBinding()
@@ -149,8 +153,54 @@ public function testMooBinding()
149153
$key = md5(json_encode($binding));
150154
$name = sprintf('old_sound_rabbit_mq.%s_binding', $key);
151155
$this->assertTrue($container->has($name));
156+
$definition = $container->getDefinition($name);
157+
$this->assertEquals((string) $definition->getArgument(0), 'old_sound_rabbit_mq.connection.default2');
158+
$this->assertBindingMethodCalls($definition, $binding);
152159
}
153160

161+
protected function assertBindingMethodCalls(Definition $definition, $binding)
162+
{
163+
$this->assertEquals(array(
164+
array(
165+
'setArguments',
166+
array(
167+
$binding['arguments']
168+
)
169+
),
170+
array(
171+
'setDestination',
172+
array(
173+
$binding['destination']
174+
)
175+
),
176+
array(
177+
'setDestinationIsExchange',
178+
array(
179+
$binding['destination_is_exchange']
180+
)
181+
),
182+
array(
183+
'setExchange',
184+
array(
185+
$binding['exchange']
186+
)
187+
),
188+
array(
189+
'isNowait',
190+
array(
191+
$binding['nowait']
192+
)
193+
),
194+
array(
195+
'setRoutingKey',
196+
array(
197+
$binding['routing_key']
198+
)
199+
),
200+
),
201+
$definition->getMethodCalls()
202+
);
203+
}
154204
public function testFooProducerDefinition()
155205
{
156206
$container = $this->getContainer('test.yml');

0 commit comments

Comments
 (0)