Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9670e9f

Browse filesBrowse files
jderussenicolas-grekas
authored andcommitted
[Lock][Messenger] Fix precedence of DSN options for 5.1
1 parent 86c79ce commit 9670e9f
Copy full SHA for 9670e9f

File tree

4 files changed

+33
-11
lines changed
Filter options

4 files changed

+33
-11
lines changed

‎src/Symfony/Component/Lock/Store/MongoDbStore.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Store/MongoDbStore.php
+2-2Lines 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
}

‎src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Tests/Store/MongoDbStoreTest.php
+13Lines 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
*/

‎src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ public function testFromDsn()
7070
);
7171
}
7272

73+
public function testDsnPrecedence()
74+
{
75+
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
76+
$this->assertEquals(
77+
new Connection(['queue_name' => 'queue_dsn'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)),
78+
Connection::fromDsn('sqs://key_dsn:secret_dsn@default/queue_dsn?region=us-east-2', ['region' => 'eu-west-3', 'queue_name' => 'queue_options', 'access_key' => 'key_option', 'secret_key' => 'secret_option'], $httpClient)
79+
);
80+
}
81+
7382
public function testFromDsnWithRegion()
7483
{
7584
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();

‎src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
9494
if (isset($parsedUrl['query'])) {
9595
parse_str($parsedUrl['query'], $query);
9696
}
97-
97+
$options = $query + $options + self::DEFAULT_OPTIONS;
9898
$configuration = [
99-
'buffer_size' => $options['buffer_size'] ?? (int) ($query['buffer_size'] ?? self::DEFAULT_OPTIONS['buffer_size']),
100-
'wait_time' => $options['wait_time'] ?? (int) ($query['wait_time'] ?? self::DEFAULT_OPTIONS['wait_time']),
101-
'poll_timeout' => $options['poll_timeout'] ?? ($query['poll_timeout'] ?? self::DEFAULT_OPTIONS['poll_timeout']),
102-
'visibility_timeout' => $options['visibility_timeout'] ?? ($query['visibility_timeout'] ?? self::DEFAULT_OPTIONS['visibility_timeout']),
103-
'auto_setup' => $options['auto_setup'] ?? (bool) ($query['auto_setup'] ?? self::DEFAULT_OPTIONS['auto_setup']),
99+
'buffer_size' => (int) $options['buffer_size'],
100+
'wait_time' => (int) $options['wait_time'],
101+
'poll_timeout' => $options['poll_timeout'],
102+
'visibility_timeout' => $options['visibility_timeout'],
103+
'auto_setup' => (bool) $options['auto_setup'],
104104
];
105105

106106
$clientConfiguration = [
107-
'region' => $options['region'] ?? ($query['region'] ?? self::DEFAULT_OPTIONS['region']),
108-
'accessKeyId' => $options['access_key'] ?? (urldecode($parsedUrl['user'] ?? '') ?: self::DEFAULT_OPTIONS['access_key']),
109-
'accessKeySecret' => $options['secret_key'] ?? (urldecode($parsedUrl['pass'] ?? '') ?: self::DEFAULT_OPTIONS['secret_key']),
107+
'region' => $options['region'],
108+
'accessKeyId' => urldecode($parsedUrl['user'] ?? '') ?: $options['access_key'] ?? self::DEFAULT_OPTIONS['access_key'],
109+
'accessKeySecret' => urldecode($parsedUrl['pass'] ?? '') ?: $options['secret_key'] ?? self::DEFAULT_OPTIONS['secret_key'],
110110
];
111111
unset($query['region']);
112112

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.