Skip to content

Commit 6fa8aef

Browse files
committed
fix tests.
1 parent d6cd4c4 commit 6fa8aef

5 files changed

Lines changed: 150 additions & 154 deletions

File tree

‎docker-compose.yml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ services:
2828
- MYSQL_DSN=mysql://root:rootpass@mysql/mqdev
2929
- PREDIS_DSN=redis+predis://redis
3030
- PHPREDIS_DSN=redis+phpredis://redis
31+
- GPS_DSN=gps:?projectId=mqdev&emulatorHost=http%%3A%%2F%%2Fgoogle-pubsub%%3A8085 # encoded http://google-pubsub:8085
3132
- RABBITMQ_HOST=rabbitmq
3233
- RABBITMQ_USER=guest
3334
- RABBITMQ_PASSWORD=guest
@@ -53,8 +54,6 @@ services:
5354
- GEARMAN_DSN=gearman://gearmand:4730
5455
- RDKAFKA_HOST=kafka
5556
- RDKAFKA_PORT=9092
56-
- PUBSUB_EMULATOR_HOST=http://google-pubsub:8085
57-
- GCLOUD_PROJECT=mqdev
5857
- MONGO_DSN=mongodb://mongo
5958

6059
rabbitmq:

‎pkg/enqueue-bundle/Tests/Functional/App/config/custom-config.yml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ services:
3434

3535
test.sqs_client:
3636
public: true
37-
class: Aws\Sqs\SqsClient
37+
class: 'Aws\Sqs\SqsClient'
3838
arguments:
3939
-
4040
endpoint: '%env(AWS_SQS_ENDPOINT)%'
@@ -43,3 +43,7 @@ services:
4343
credentials:
4444
key: '%env(AWS_SQS_KEY)%'
4545
secret: '%env(AWS_SQS_SECRET)%'
46+
47+
test.sqs_custom_connection_factory_factory:
48+
class: 'Enqueue\Bundle\Tests\Functional\App\SqsCustomConnectionFactoryFactory'
49+
arguments: ['@service_container']

‎pkg/enqueue-bundle/Tests/Functional/UseCasesTest.php‎

Lines changed: 112 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Interop\Queue\PsrContext;
1313
use Interop\Queue\PsrMessage;
1414
use Interop\Queue\PsrQueue;
15+
use Interop\Queue\PurgeQueueNotSupportedException;
1516
use Symfony\Component\Console\Tester\CommandTester;
1617
use Symfony\Component\Filesystem\Filesystem;
1718
use Symfony\Component\HttpKernel\Kernel;
@@ -76,7 +77,7 @@ public function provideEnqueueConfigs()
7677

7778
yield 'rabbitmq_stomp' => [[
7879
'transport' => [
79-
'dsn' => getenv('STOMP_DSN'),
80+
'dsn' => getenv('RABITMQ_STOMP_DSN'),
8081
'lazy' => false,
8182
'management_plugin_installed' => true,
8283
],
@@ -113,17 +114,18 @@ public function provideEnqueueConfigs()
113114
yield 'sqs_client' => [[
114115
'transport' => [
115116
'dsn' => 'sqs:',
116-
'client' => 'test.sqs_client',
117+
'service' => 'test.sqs_client',
118+
'factory_service' => 'test.sqs_custom_connection_factory_factory',
117119
],
118120
]];
119121

120122
yield 'mongodb_dsn' => [[
121123
'transport' => getenv('MONGO_DSN'),
122124
]];
123125

124-
yield 'gps' => [[
125-
'transport' => 'gps:',
126-
]];
126+
// yield 'gps' => [[
127+
// 'transport' => getenv('GPS_DSN'),
128+
// ]];
127129
}
128130

129131
/**
@@ -139,117 +141,117 @@ public function testProducerSendsMessage(array $enqueueConfig)
139141

140142
$consumer = $this->getPsrContext()->createConsumer($this->getTestQueue());
141143

144+
$message = $consumer->receive(1000);
145+
$this->assertInstanceOf(PsrMessage::class, $message);
146+
$consumer->acknowledge($message);
147+
148+
$this->assertSame($expectedBody, $message->getBody());
149+
}
150+
151+
/**
152+
* @dataProvider provideEnqueueConfigs
153+
*/
154+
public function testProducerSendsCommandMessage(array $enqueueConfig)
155+
{
156+
$this->customSetUp($enqueueConfig);
157+
158+
$expectedBody = __METHOD__.time();
159+
160+
$this->getMessageProducer()->sendCommand(TestCommandProcessor::COMMAND, $expectedBody);
161+
162+
$consumer = $this->getPsrContext()->createConsumer($this->getTestQueue());
163+
142164
$message = $consumer->receive(100);
143165
$this->assertInstanceOf(PsrMessage::class, $message);
144166
$consumer->acknowledge($message);
145167

168+
$this->assertInstanceOf(PsrMessage::class, $message);
146169
$this->assertSame($expectedBody, $message->getBody());
147170
}
148171

149-
// /**
150-
// * @dataProvider provideEnqueueConfigs
151-
// */
152-
// public function testProducerSendsCommandMessage(array $enqueueConfig)
153-
// {
154-
// $this->customSetUp($enqueueConfig);
155-
//
156-
// $expectedBody = __METHOD__.time();
157-
//
158-
// $this->getMessageProducer()->sendCommand(TestCommandProcessor::COMMAND, $expectedBody);
159-
//
160-
// $consumer = $this->getPsrContext()->createConsumer($this->getTestQueue());
161-
//
162-
// $message = $consumer->receive(100);
163-
// $this->assertInstanceOf(PsrMessage::class, $message);
164-
// $consumer->acknowledge($message);
165-
//
166-
// $this->assertInstanceOf(PsrMessage::class, $message);
167-
// $this->assertSame($expectedBody, $message->getBody());
168-
// }
169-
//
170-
// /**
171-
// * @dataProvider provideEnqueueConfigs
172-
// */
173-
// public function testClientConsumeCommandMessagesFromExplicitlySetQueue(array $enqueueConfig)
174-
// {
175-
// $this->customSetUp($enqueueConfig);
176-
//
177-
// $command = static::$container->get(ConsumeMessagesCommand::class);
178-
// $processor = static::$container->get('test.message.command_processor');
179-
//
180-
// $expectedBody = __METHOD__.time();
181-
//
182-
// $this->getMessageProducer()->sendCommand(TestCommandProcessor::COMMAND, $expectedBody);
183-
//
184-
// $tester = new CommandTester($command);
185-
// $tester->execute([
186-
// '--message-limit' => 2,
187-
// '--time-limit' => 'now +10 seconds',
188-
// 'client-queue-names' => ['test'],
189-
// ]);
190-
//
191-
// $this->assertInstanceOf(PsrMessage::class, $processor->message);
192-
// $this->assertEquals($expectedBody, $processor->message->getBody());
193-
// }
194-
//
195-
// /**
196-
// * @dataProvider provideEnqueueConfigs
197-
// */
198-
// public function testClientConsumeMessagesFromExplicitlySetQueue(array $enqueueConfig)
199-
// {
200-
// $this->customSetUp($enqueueConfig);
201-
//
202-
// $expectedBody = __METHOD__.time();
203-
//
204-
// $command = static::$container->get(ConsumeMessagesCommand::class);
205-
// $processor = static::$container->get('test.message.processor');
206-
//
207-
// $this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, $expectedBody);
208-
//
209-
// $tester = new CommandTester($command);
210-
// $tester->execute([
211-
// '--message-limit' => 2,
212-
// '--time-limit' => 'now +10 seconds',
213-
// 'client-queue-names' => ['test'],
214-
// ]);
215-
//
216-
// $this->assertInstanceOf(PsrMessage::class, $processor->message);
217-
// $this->assertEquals($expectedBody, $processor->message->getBody());
218-
// }
219-
//
220-
// /**
221-
// * @dataProvider provideEnqueueConfigs
222-
// */
223-
// public function testTransportConsumeMessagesCommandShouldConsumeMessage(array $enqueueConfig)
224-
// {
225-
// $this->customSetUp($enqueueConfig);
226-
//
227-
// if ($this->getTestQueue() instanceof StompDestination) {
228-
// $this->markTestSkipped('The test fails with the exception Stomp\Exception\ErrorFrameException: Error "precondition_failed". '.
229-
// 'It happens because of the destination options are different from the one used while creating the dest. Nothing to do about it'
230-
// );
231-
// }
232-
//
233-
// $expectedBody = __METHOD__.time();
234-
//
235-
// $command = static::$container->get(ContainerAwareConsumeMessagesCommand::class);
236-
// $command->setContainer(static::$container);
237-
// $processor = static::$container->get('test.message.processor');
238-
//
239-
// $this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, $expectedBody);
240-
//
241-
// $tester = new CommandTester($command);
242-
// $tester->execute([
243-
// '--message-limit' => 1,
244-
// '--time-limit' => '+10sec',
245-
// '--receive-timeout' => 1000,
246-
// '--queue' => [$this->getTestQueue()->getQueueName()],
247-
// 'processor-service' => 'test.message.processor',
248-
// ]);
249-
//
250-
// $this->assertInstanceOf(PsrMessage::class, $processor->message);
251-
// $this->assertEquals($expectedBody, $processor->message->getBody());
252-
// }
172+
/**
173+
* @dataProvider provideEnqueueConfigs
174+
*/
175+
public function testClientConsumeCommandMessagesFromExplicitlySetQueue(array $enqueueConfig)
176+
{
177+
$this->customSetUp($enqueueConfig);
178+
179+
$command = static::$container->get(ConsumeMessagesCommand::class);
180+
$processor = static::$container->get('test.message.command_processor');
181+
182+
$expectedBody = __METHOD__.time();
183+
184+
$this->getMessageProducer()->sendCommand(TestCommandProcessor::COMMAND, $expectedBody);
185+
186+
$tester = new CommandTester($command);
187+
$tester->execute([
188+
'--message-limit' => 2,
189+
'--time-limit' => 'now +10 seconds',
190+
'client-queue-names' => ['test'],
191+
]);
192+
193+
$this->assertInstanceOf(PsrMessage::class, $processor->message);
194+
$this->assertEquals($expectedBody, $processor->message->getBody());
195+
}
196+
197+
/**
198+
* @dataProvider provideEnqueueConfigs
199+
*/
200+
public function testClientConsumeMessagesFromExplicitlySetQueue(array $enqueueConfig)
201+
{
202+
$this->customSetUp($enqueueConfig);
203+
204+
$expectedBody = __METHOD__.time();
205+
206+
$command = static::$container->get(ConsumeMessagesCommand::class);
207+
$processor = static::$container->get('test.message.processor');
208+
209+
$this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, $expectedBody);
210+
211+
$tester = new CommandTester($command);
212+
$tester->execute([
213+
'--message-limit' => 2,
214+
'--time-limit' => 'now +10 seconds',
215+
'client-queue-names' => ['test'],
216+
]);
217+
218+
$this->assertInstanceOf(PsrMessage::class, $processor->message);
219+
$this->assertEquals($expectedBody, $processor->message->getBody());
220+
}
221+
222+
/**
223+
* @dataProvider provideEnqueueConfigs
224+
*/
225+
public function testTransportConsumeMessagesCommandShouldConsumeMessage(array $enqueueConfig)
226+
{
227+
$this->customSetUp($enqueueConfig);
228+
229+
if ($this->getTestQueue() instanceof StompDestination) {
230+
$this->markTestSkipped('The test fails with the exception Stomp\Exception\ErrorFrameException: Error "precondition_failed". '.
231+
'It happens because of the destination options are different from the one used while creating the dest. Nothing to do about it'
232+
);
233+
}
234+
235+
$expectedBody = __METHOD__.time();
236+
237+
$command = static::$container->get(ContainerAwareConsumeMessagesCommand::class);
238+
$command->setContainer(static::$container);
239+
$processor = static::$container->get('test.message.processor');
240+
241+
$this->getMessageProducer()->sendEvent(TestProcessor::TOPIC, $expectedBody);
242+
243+
$tester = new CommandTester($command);
244+
$tester->execute([
245+
'--message-limit' => 1,
246+
'--time-limit' => '+10sec',
247+
'--receive-timeout' => 1000,
248+
'--queue' => [$this->getTestQueue()->getQueueName()],
249+
'processor-service' => 'test.message.processor',
250+
]);
251+
252+
$this->assertInstanceOf(PsrMessage::class, $processor->message);
253+
$this->assertEquals($expectedBody, $processor->message->getBody());
254+
}
253255

254256
/**
255257
* @return string
@@ -278,7 +280,7 @@ protected function customSetUp(array $enqueueConfig)
278280

279281
try {
280282
$context->purgeQueue($this->getTestQueue());
281-
} catch (\Exception $e) {
283+
} catch (PurgeQueueNotSupportedException $e) {
282284
}
283285
}
284286

‎pkg/enqueue/Client/DriverFactory.php‎

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,13 @@ public function create(PsrConnectionFactory $factory, string $dsn, array $config
5555
));
5656
}
5757

58-
if (false == isset($config['management_plugin_installed'])) {
59-
throw new \LogicException(sprintf('Scheme %s requires the management plugin is to be installed', $dsn->getScheme()));
60-
}
61-
62-
if (isset($config['rabbitmq_management_dsn'])) {
63-
$managementDsn = new Dsn($config['rabbitmq_management_dsn']);
64-
65-
$managementClient = StompManagementClient::create(
66-
ltrim($managementDsn->getPath(), '/'),
67-
$managementDsn->getHost(),
68-
$managementDsn->getPort(),
69-
$managementDsn->getUser(),
70-
$managementDsn->getPassword()
71-
);
72-
} else {
73-
$managementClient = StompManagementClient::create(
74-
ltrim($dsn->getPath(), '/'),
75-
$dsn->getHost(),
76-
isset($config['management_plugin_port']) ? $config['management_plugin_port'] : 15672,
77-
$dsn->getUser(),
78-
$dsn->getPassword()
79-
);
80-
}
58+
$managementClient = StompManagementClient::create(
59+
ltrim($dsn->getPath(), '/'),
60+
$dsn->getHost(),
61+
isset($config['management_plugin_port']) ? $config['management_plugin_port'] : 15672,
62+
$dsn->getUser(),
63+
$dsn->getPassword()
64+
);
8165

8266
return new RabbitMqStompDriver($factory->createContext(), $this->config, $this->queueMetaRegistry, $managementClient);
8367
}
@@ -104,23 +88,34 @@ public function create(PsrConnectionFactory $factory, string $dsn, array $config
10488
private function findDriverClass(Dsn $dsn, array $factories): ?string
10589
{
10690
$protocol = $dsn->getSchemeProtocol();
107-
foreach ($factories as $driverClass => $info) {
108-
if (false == in_array($protocol, $info['schemes'], true)) {
109-
continue;
110-
}
11191

112-
if (empty($info['requiredSchemeExtensions'])) {
113-
return $driverClass;
92+
if ($dsn->getSchemeExtensions()) {
93+
foreach ($factories as $driverClass => $info) {
94+
if (empty($info['requiredSchemeExtensions'])) {
95+
continue;
96+
}
97+
98+
if (false == in_array($protocol, $info['schemes'], true)) {
99+
continue;
100+
}
101+
102+
$diff = array_diff($dsn->getSchemeExtensions(), $info['requiredSchemeExtensions']);
103+
if (empty($diff)) {
104+
return $driverClass;
105+
}
114106
}
107+
}
115108

116-
if (false == $dsn->getSchemeExtensions()) {
117-
return null;
109+
foreach ($factories as $driverClass => $info) {
110+
if (false == empty($info['requiredSchemeExtensions'])) {
111+
continue;
118112
}
119113

120-
$diff = array_diff($dsn->getSchemeExtensions(), $info['requiredSchemeExtensions']);
121-
if (empty($diff)) {
122-
return $driverClass;
114+
if (false == in_array($protocol, $info['schemes'], true)) {
115+
continue;
123116
}
117+
118+
return $driverClass;
124119
}
125120

126121
return null;

0 commit comments

Comments
 (0)