From b44a6e8e794fe6ddf17a0cef3afa4b4c07677814 Mon Sep 17 00:00:00 2001 From: Jak Spalding Date: Thu, 6 Dec 2018 19:56:21 +0000 Subject: [PATCH] fix: polling_interval is an integer --- pkg/mongodb/MongodbConnectionFactory.php | 2 +- pkg/mongodb/Tests/MongodbConnectionFactoryTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pkg/mongodb/MongodbConnectionFactory.php b/pkg/mongodb/MongodbConnectionFactory.php index 28a5fc068..a5148f1c0 100644 --- a/pkg/mongodb/MongodbConnectionFactory.php +++ b/pkg/mongodb/MongodbConnectionFactory.php @@ -98,7 +98,7 @@ public static function parseDsn(string $dsn): array parse_str($parsedUrl['query'], $queryParts); //get enqueue attributes values if (!empty($queryParts['polling_interval'])) { - $config['polling_interval'] = $queryParts['polling_interval']; + $config['polling_interval'] = (int) $queryParts['polling_interval']; } if (!empty($queryParts['enqueue_collection'])) { $config['collection_name'] = $queryParts['enqueue_collection']; diff --git a/pkg/mongodb/Tests/MongodbConnectionFactoryTest.php b/pkg/mongodb/Tests/MongodbConnectionFactoryTest.php index 63ec00cea..c15b0fa43 100644 --- a/pkg/mongodb/Tests/MongodbConnectionFactoryTest.php +++ b/pkg/mongodb/Tests/MongodbConnectionFactoryTest.php @@ -45,6 +45,20 @@ public function testCouldBeConstructedWithCustomConfiguration() $this->assertAttributeEquals($params, 'config', $factory); } + public function testCouldBeConstructedWithCustomConfigurationFromDsn() + { + $params = [ + 'dsn' => 'mongodb://127.0.0.3/test-db-name?enqueue_collection=collection-name&polling_interval=3000', + 'dbname' => 'test-db-name', + 'collection_name' => 'collection-name', + 'polling_interval' => 3000, + ]; + + $factory = new MongodbConnectionFactory($params['dsn']); + + $this->assertAttributeEquals($params, 'config', $factory); + } + public function testShouldCreateContext() { $factory = new MongodbConnectionFactory();