Skip to content

Commit 76fbdfa

Browse files
authored
Merge pull request #486 from php-enqueue/fix-simple-client-dsn-issue
simple client dsn issue
2 parents a0026a1 + 76a748d commit 76fbdfa

File tree

2 files changed

+118
-1
lines changed

2 files changed

+118
-1
lines changed

Diff for: pkg/simple-client/SimpleClient.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ class_exists(AmqpLibConnectionFactory::class)
377377
*/
378378
private function buildConfig($config)
379379
{
380-
if (is_string($config) && false !== strpos($config, '://')) {
380+
if (is_string($config) && false !== strpos($config, ':')) {
381381
$extConfig = [
382382
'client' => [],
383383
'transport' => [

Diff for: pkg/simple-client/Tests/SimpleClientTest.php

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
namespace Enqueue\SimpleClient\Tests;
4+
5+
use Enqueue\Consumption\Result;
6+
use Enqueue\SimpleClient\SimpleClient;
7+
use Enqueue\Test\RabbitManagementExtensionTrait;
8+
use Enqueue\Test\RabbitmqAmqpExtension;
9+
use Interop\Queue\PsrContext;
10+
use Interop\Queue\PsrMessage;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* @group functional
15+
*/
16+
class SimpleClientTest extends TestCase
17+
{
18+
use RabbitmqAmqpExtension;
19+
use RabbitManagementExtensionTrait;
20+
21+
public function setUp()
22+
{
23+
if (false == getenv('RABBITMQ_HOST')) {
24+
throw new \PHPUnit_Framework_SkippedTestError('Functional tests are not allowed in this environment');
25+
}
26+
27+
$this->removeQueue('enqueue.app.default');
28+
}
29+
30+
public function transportConfigDataProvider()
31+
{
32+
yield 'amqp' => [[
33+
'transport' => [
34+
'default' => 'amqp',
35+
'amqp' => [
36+
'driver' => 'ext',
37+
'host' => getenv('RABBITMQ_HOST'),
38+
'port' => getenv('RABBITMQ_AMQP__PORT'),
39+
'user' => getenv('RABBITMQ_USER'),
40+
'pass' => getenv('RABBITMQ_PASSWORD'),
41+
'vhost' => getenv('RABBITMQ_VHOST'),
42+
],
43+
],
44+
]];
45+
46+
yield 'config_as_dsn_string' => [getenv('AMQP_DSN')];
47+
48+
yield 'config_as_dsn_without_host' => ['amqp:?lazy=1'];
49+
50+
yield 'amqp_dsn' => [[
51+
'transport' => [
52+
'default' => 'amqp',
53+
'amqp' => getenv('AMQP_DSN'),
54+
],
55+
]];
56+
57+
yield 'default_amqp_as_dsn' => [[
58+
'transport' => [
59+
'default' => getenv('AMQP_DSN'),
60+
],
61+
]];
62+
63+
yield [[
64+
'transport' => [
65+
'default' => 'rabbitmq_amqp',
66+
'rabbitmq_amqp' => [
67+
'driver' => 'ext',
68+
'host' => getenv('RABBITMQ_HOST'),
69+
'port' => getenv('RABBITMQ_AMQP__PORT'),
70+
'user' => getenv('RABBITMQ_USER'),
71+
'pass' => getenv('RABBITMQ_PASSWORD'),
72+
'vhost' => getenv('RABBITMQ_VHOST'),
73+
],
74+
],
75+
]];
76+
77+
yield [[
78+
'transport' => [
79+
'default' => 'rabbitmq_amqp',
80+
'rabbitmq_amqp' => [
81+
'driver' => 'ext',
82+
'host' => getenv('RABBITMQ_HOST'),
83+
'port' => getenv('RABBITMQ_AMQP__PORT'),
84+
'user' => getenv('RABBITMQ_USER'),
85+
'pass' => getenv('RABBITMQ_PASSWORD'),
86+
'vhost' => getenv('RABBITMQ_VHOST'),
87+
],
88+
],
89+
]];
90+
91+
yield 'mongodb_dsn' => [[
92+
'transport' => [
93+
'default' => 'mongodb',
94+
'mongodb' => getenv('MONGO_DSN'),
95+
],
96+
]];
97+
}
98+
99+
/**
100+
* @dataProvider transportConfigDataProvider
101+
*
102+
* @param mixed $config
103+
*/
104+
public function testProduceAndConsumeOneMessage($config)
105+
{
106+
$actualMessage = null;
107+
108+
$client = new SimpleClient($config);
109+
$client->bind('foo_topic', 'foo_processor', function (PsrMessage $message) use (&$actualMessage) {
110+
$actualMessage = $message;
111+
112+
return Result::ACK;
113+
});
114+
115+
$this->assertInstanceOf(PsrContext::class, $client->getContext());
116+
}
117+
}

0 commit comments

Comments
 (0)