Skip to content

Commit 1c7ac88

Browse files
jderussenicolas-grekas
authored andcommitted
[Lock][Messenger] Fix precedence of DSN options for 5.1
1 parent 5c40fa8 commit 1c7ac88

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Store/MongoDbStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public function __construct($mongo, array $options = [], float $initialTtl = 300
120120
if (isset($parsedUrl['query'])) {
121121
parse_str($parsedUrl['query'], $query);
122122
}
123-
$this->options['collection'] = $this->options['collection'] ?? $query['collection'] ?? null;
124-
$this->options['database'] = $this->options['database'] ?? ltrim($parsedUrl['path'] ?? '', '/') ?: null;
123+
$this->options['collection'] = $query['collection'] ?? $this->options['collection'] ?? null;
124+
$this->options['database'] = ltrim($parsedUrl['path'] ?? '', '/') ?: $this->options['database'] ?? null;
125125
if (null === $this->options['database']) {
126126
throw new InvalidArgumentException(sprintf('"%s()" requires the "database" in the URI path or option when constructing with a URI.', __METHOD__));
127127
}

Tests/Store/MongoDbStoreTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ public function provideConstructorArgs()
121121
yield ['mongodb://localhost/', ['database' => 'test', 'collection' => 'lock']];
122122
}
123123

124+
public function testDsnPrecedence()
125+
{
126+
$client = self::getMongoClient();
127+
128+
$store = new MongoDbStore('mongodb://localhost/test_dsn?collection=lock_dns', ['collection' => 'lock_option', 'database' => 'test_option']);
129+
$r = new \ReflectionObject($store);
130+
$p = $r->getProperty('options');
131+
$p->setAccessible(true);
132+
$options = $p->getValue($store);
133+
$this->assertSame('lock_dns', $options['collection']);
134+
$this->assertSame('test_dsn', $options['database']);
135+
}
136+
124137
/**
125138
* @dataProvider provideInvalidConstructorArgs
126139
*/

0 commit comments

Comments
 (0)