Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed275f0

Browse files
committed
[Messenger] fix ignore account & endpoint options amazon sqs connection
1 parent 08ff65f commit ed275f0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,17 @@ public function testFromDsnWithQueueNameOption()
139139
);
140140
}
141141

142+
public function testFromDsnWithAccountAndEndpointOption()
143+
{
144+
$httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock();
145+
146+
$this->assertEquals(
147+
new Connection(['account' => 12345], new SqsClient(['endpoint' => 'https://custom-endpoint.tld', 'region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),
148+
Connection::fromDsn('sqs://default', ['endpoint' => 'https://custom-endpoint.tld', 'account' => 12345], $httpClient)
149+
);
150+
}
151+
152+
142153
public function testKeepGettingPendingMessages()
143154
{
144155
$client = $this->createMock(SqsClient::class);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,15 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
117117
$clientConfiguration['region'] = $matches[1];
118118
}
119119
unset($query['sslmode']);
120+
} elseif (self::DEFAULT_OPTIONS['endpoint'] !== $options['endpoint'] ?? self::DEFAULT_OPTIONS['endpoint']) {
121+
$clientConfiguration['endpoint'] = $options['endpoint'];
120122
}
121123

122124
$parsedPath = explode('/', ltrim($parsedUrl['path'] ?? '/', '/'));
123125
if (\count($parsedPath) > 0 && !empty($queueName = end($parsedPath))) {
124126
$configuration['queue_name'] = $queueName;
125127
}
126-
$configuration['account'] = 2 === \count($parsedPath) ? $parsedPath[0] : null;
128+
$configuration['account'] = 2 === \count($parsedPath) ? $parsedPath[0] : $options['account'] ?? self::DEFAULT_OPTIONS['account'];
127129

128130
// check for extra keys in options
129131
$optionsExtraKeys = array_diff(array_keys($options), array_keys(self::DEFAULT_OPTIONS));

0 commit comments

Comments
 (0)