From a886d64602d56a67c886be6c21547775050b9d27 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 3 Aug 2018 21:06:05 +0300 Subject: [PATCH] simple client dsn issue --- pkg/simple-client/SimpleClient.php | 2 +- pkg/simple-client/Tests/SimpleClientTest.php | 117 +++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 pkg/simple-client/Tests/SimpleClientTest.php diff --git a/pkg/simple-client/SimpleClient.php b/pkg/simple-client/SimpleClient.php index 000743259..8114de2e2 100644 --- a/pkg/simple-client/SimpleClient.php +++ b/pkg/simple-client/SimpleClient.php @@ -377,7 +377,7 @@ class_exists(AmqpLibConnectionFactory::class) */ private function buildConfig($config) { - if (is_string($config) && false !== strpos($config, '://')) { + if (is_string($config) && false !== strpos($config, ':')) { $extConfig = [ 'client' => [], 'transport' => [ diff --git a/pkg/simple-client/Tests/SimpleClientTest.php b/pkg/simple-client/Tests/SimpleClientTest.php new file mode 100644 index 000000000..3ff8badf9 --- /dev/null +++ b/pkg/simple-client/Tests/SimpleClientTest.php @@ -0,0 +1,117 @@ +removeQueue('enqueue.app.default'); + } + + public function transportConfigDataProvider() + { + yield 'amqp' => [[ + 'transport' => [ + 'default' => 'amqp', + 'amqp' => [ + 'driver' => 'ext', + 'host' => getenv('RABBITMQ_HOST'), + 'port' => getenv('RABBITMQ_AMQP__PORT'), + 'user' => getenv('RABBITMQ_USER'), + 'pass' => getenv('RABBITMQ_PASSWORD'), + 'vhost' => getenv('RABBITMQ_VHOST'), + ], + ], + ]]; + + yield 'config_as_dsn_string' => [getenv('AMQP_DSN')]; + + yield 'config_as_dsn_without_host' => ['amqp:?lazy=1']; + + yield 'amqp_dsn' => [[ + 'transport' => [ + 'default' => 'amqp', + 'amqp' => getenv('AMQP_DSN'), + ], + ]]; + + yield 'default_amqp_as_dsn' => [[ + 'transport' => [ + 'default' => getenv('AMQP_DSN'), + ], + ]]; + + yield [[ + 'transport' => [ + 'default' => 'rabbitmq_amqp', + 'rabbitmq_amqp' => [ + 'driver' => 'ext', + 'host' => getenv('RABBITMQ_HOST'), + 'port' => getenv('RABBITMQ_AMQP__PORT'), + 'user' => getenv('RABBITMQ_USER'), + 'pass' => getenv('RABBITMQ_PASSWORD'), + 'vhost' => getenv('RABBITMQ_VHOST'), + ], + ], + ]]; + + yield [[ + 'transport' => [ + 'default' => 'rabbitmq_amqp', + 'rabbitmq_amqp' => [ + 'driver' => 'ext', + 'host' => getenv('RABBITMQ_HOST'), + 'port' => getenv('RABBITMQ_AMQP__PORT'), + 'user' => getenv('RABBITMQ_USER'), + 'pass' => getenv('RABBITMQ_PASSWORD'), + 'vhost' => getenv('RABBITMQ_VHOST'), + ], + ], + ]]; + + yield 'mongodb_dsn' => [[ + 'transport' => [ + 'default' => 'mongodb', + 'mongodb' => getenv('MONGO_DSN'), + ], + ]]; + } + + /** + * @dataProvider transportConfigDataProvider + * + * @param mixed $config + */ + public function testProduceAndConsumeOneMessage($config) + { + $actualMessage = null; + + $client = new SimpleClient($config); + $client->bind('foo_topic', 'foo_processor', function (PsrMessage $message) use (&$actualMessage) { + $actualMessage = $message; + + return Result::ACK; + }); + + $this->assertInstanceOf(PsrContext::class, $client->getContext()); + } +}