From 3aace61432188e1539cabd77db49d94103e4b901 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 30 Nov 2018 14:22:06 +0200 Subject: [PATCH] [sqs] Use a queue created in another AWS account. --- pkg/sqs/SqsConnectionFactory.php | 23 ++++--- pkg/sqs/SqsContext.php | 17 +++-- pkg/sqs/Tests/Spec/CreateSqsQueueTrait.php | 21 ++++++ ...dAndReceiveDelayedMessageFromQueueTest.php | 25 ++----- .../Spec/SqsSendToAndReceiveFromQueueTest.php | 25 ++----- .../Spec/SqsSendToAndReceiveFromTopicTest.php | 25 ++----- ...SqsSendToAndReceiveNoWaitFromQueueTest.php | 32 +++++++-- ...SqsSendToAndReceiveNoWaitFromTopicTest.php | 32 +++++++-- .../SqsSendToTopicAndReceiveFromQueueTest.php | 37 ++++++++-- ...ndToTopicAndReceiveNoWaitFromQueueTest.php | 37 ++++++++-- .../Tests/SqsConnectionFactoryConfigTest.php | 7 ++ pkg/sqs/Tests/SqsConnectionFactoryTest.php | 5 +- pkg/sqs/Tests/SqsContextTest.php | 68 ++++++++++++++----- 13 files changed, 231 insertions(+), 123 deletions(-) create mode 100644 pkg/sqs/Tests/Spec/CreateSqsQueueTrait.php diff --git a/pkg/sqs/SqsConnectionFactory.php b/pkg/sqs/SqsConnectionFactory.php index 5f626c368..82e8f1ae1 100644 --- a/pkg/sqs/SqsConnectionFactory.php +++ b/pkg/sqs/SqsConnectionFactory.php @@ -23,14 +23,15 @@ class SqsConnectionFactory implements ConnectionFactory /** * $config = [ - * 'key' => null - AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment. - * 'secret' => null, - AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment. - * 'token' => null, - AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment. - * 'region' => null, - (string, required) Region to connect to. See http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of available regions. - * 'retries' => 3, - (int, default=int(3)) Configures the maximum number of allowed retries for a client (pass 0 to disable retries). - * 'version' => '2012-11-05', - (string, required) The version of the webservice to utilize - * 'lazy' => true, - Enable lazy connection (boolean) - * 'endpoint' => null - (string, default=null) The full URI of the webservice. This is only required when connecting to a custom endpoint e.g. localstack + * 'key' => null AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment. + * 'secret' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment. + * 'token' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment. + * 'region' => null, (string, required) Region to connect to. See http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of available regions. + * 'retries' => 3, (int, default=int(3)) Configures the maximum number of allowed retries for a client (pass 0 to disable retries). + * 'version' => '2012-11-05', (string, required) The version of the webservice to utilize + * 'lazy' => true, Enable lazy connection (boolean) + * 'endpoint' => null (string, default=null) The full URI of the webservice. This is only required when connecting to a custom endpoint e.g. localstack + * 'queue_owner_aws_account_id' The AWS account ID of the account that created the queue. * ]. * * or @@ -74,10 +75,10 @@ public function createContext(): Context if ($this->config['lazy']) { return new SqsContext(function () { return $this->establishConnection(); - }); + }, $this->config); } - return new SqsContext($this->establishConnection()); + return new SqsContext($this->establishConnection(), $this->config); } private function establishConnection(): SqsClient @@ -132,6 +133,7 @@ private function parseDsn(string $dsn): array 'version' => $dsn->getString('version'), 'lazy' => $dsn->getBool('lazy'), 'endpoint' => $dsn->getString('endpoint'), + 'queue_owner_aws_account_id' => $dsn->getString('queue_owner_aws_account_id'), ]), function ($value) { return null !== $value; }); } @@ -146,6 +148,7 @@ private function defaultConfig(): array 'version' => '2012-11-05', 'lazy' => true, 'endpoint' => null, + 'queue_owner_aws_account_id' => null, ]; } } diff --git a/pkg/sqs/SqsContext.php b/pkg/sqs/SqsContext.php index cb3a9edfa..810145b1a 100644 --- a/pkg/sqs/SqsContext.php +++ b/pkg/sqs/SqsContext.php @@ -34,12 +34,14 @@ class SqsContext implements Context */ private $queueUrls; + private $config; + /** * Callable must return instance of SqsClient once called. * * @param SqsClient|callable $client */ - public function __construct($client) + public function __construct($client, array $config) { if ($client instanceof SqsClient) { $this->client = $client; @@ -52,6 +54,8 @@ public function __construct($client) SqsClient::class )); } + + $this->config = $config; } /** @@ -148,15 +152,18 @@ public function getQueueUrl(SqsDestination $destination): string return $this->queueUrls[$destination->getQueueName()]; } - $result = $this->getClient()->getQueueUrl([ - 'QueueName' => $destination->getQueueName(), - ]); + $arguments = ['QueueName' => $destination->getQueueName()]; + if (false == empty($this->config['queue_owner_aws_account_id'])) { + $arguments['QueueOwnerAWSAccountId'] = $this->config['queue_owner_aws_account_id']; + } + + $result = $this->getClient()->getQueueUrl($arguments); if (false == $result->hasKey('QueueUrl')) { throw new \RuntimeException(sprintf('QueueUrl cannot be resolved. queueName: "%s"', $destination->getQueueName())); } - return $this->queueUrls[$destination->getQueueName()] = $result->get('QueueUrl'); + return $this->queueUrls[$destination->getQueueName()] = (string) $result->get('QueueUrl'); } public function declareQueue(SqsDestination $dest): void diff --git a/pkg/sqs/Tests/Spec/CreateSqsQueueTrait.php b/pkg/sqs/Tests/Spec/CreateSqsQueueTrait.php new file mode 100644 index 000000000..79af8208e --- /dev/null +++ b/pkg/sqs/Tests/Spec/CreateSqsQueueTrait.php @@ -0,0 +1,21 @@ +queue = $context->createQueue($queueName); + $context->declareQueue($this->queue); + + return $this->queue; + } +} diff --git a/pkg/sqs/Tests/Spec/SqsSendAndReceiveDelayedMessageFromQueueTest.php b/pkg/sqs/Tests/Spec/SqsSendAndReceiveDelayedMessageFromQueueTest.php index 2c8f2a21a..710e918f3 100644 --- a/pkg/sqs/Tests/Spec/SqsSendAndReceiveDelayedMessageFromQueueTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendAndReceiveDelayedMessageFromQueueTest.php @@ -17,17 +17,13 @@ class SqsSendAndReceiveDelayedMessageFromQueueTest extends SendAndReceiveDelayed { use RetryTrait; use SqsExtension; + use CreateSqsQueueTrait; /** * @var SqsContext */ private $context; - /** - * @var SqsDestination - */ - private $queue; - protected function tearDown() { parent::tearDown(); @@ -37,26 +33,13 @@ protected function tearDown() } } - /** - * {@inheritdoc} - */ - protected function createContext() + protected function createContext(): SqsContext { return $this->context = $this->buildSqsContext(); } - /** - * {@inheritdoc} - * - * @param SqsContext $context - */ - protected function createQueue(Context $context, $queueName) + protected function createQueue(Context $context, $queueName): SqsDestination { - $queueName = $queueName.time(); - - $this->queue = $context->createQueue($queueName); - $context->declareQueue($this->queue); - - return $this->queue; + return $this->createSqsQueue($context, $queueName); } } diff --git a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromQueueTest.php b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromQueueTest.php index 934dda60e..780aca4c1 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromQueueTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromQueueTest.php @@ -14,17 +14,13 @@ class SqsSendToAndReceiveFromQueueTest extends SendToAndReceiveFromQueueSpec { use SqsExtension; + use CreateSqsQueueTrait; /** * @var SqsContext */ private $context; - /** - * @var SqsDestination - */ - private $queue; - protected function tearDown() { parent::tearDown(); @@ -34,26 +30,13 @@ protected function tearDown() } } - /** - * {@inheritdoc} - */ - protected function createContext() + protected function createContext(): SqsContext { return $this->context = $this->buildSqsContext(); } - /** - * {@inheritdoc} - * - * @param SqsContext $context - */ - protected function createQueue(Context $context, $queueName) + protected function createQueue(Context $context, $queueName): SqsDestination { - $queueName = $queueName.time(); - - $this->queue = $context->createQueue($queueName); - $context->declareQueue($this->queue); - - return $this->queue; + return $this->createSqsQueue($context, $queueName); } } diff --git a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromTopicTest.php b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromTopicTest.php index f21e33903..b66631233 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromTopicTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveFromTopicTest.php @@ -17,17 +17,13 @@ class SqsSendToAndReceiveFromTopicTest extends SendToAndReceiveFromTopicSpec { use SqsExtension; use RetryTrait; + use CreateSqsQueueTrait; /** * @var SqsContext */ private $context; - /** - * @var SqsDestination - */ - private $queue; - protected function tearDown() { parent::tearDown(); @@ -37,26 +33,13 @@ protected function tearDown() } } - /** - * {@inheritdoc} - */ - protected function createContext() + protected function createContext(): SqsContext { return $this->context = $this->buildSqsContext(); } - /** - * {@inheritdoc} - * - * @param SqsContext $context - */ - protected function createTopic(Context $context, $topicName) + protected function createTopic(Context $context, $queueName): SqsDestination { - $topicName = $topicName.time(); - - $this->queue = $context->createTopic($topicName); - $context->declareQueue($this->queue); - - return $this->queue; + return $this->createSqsQueue($context, $queueName); } } diff --git a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromQueueTest.php b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromQueueTest.php index 9301c647b..bb4890cc6 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromQueueTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromQueueTest.php @@ -2,6 +2,10 @@ namespace Enqueue\Sqs\Tests\Spec; +use Enqueue\Sqs\SqsContext; +use Enqueue\Sqs\SqsDestination; +use Enqueue\Test\SqsExtension; +use Interop\Queue\Context; use Interop\Queue\Spec\SendToAndReceiveNoWaitFromQueueSpec; /** @@ -9,16 +13,30 @@ */ class SqsSendToAndReceiveNoWaitFromQueueTest extends SendToAndReceiveNoWaitFromQueueSpec { - public function test() - { - $this->markTestSkipped('The test is fragile. This is how SQS.'); - } + use SqsExtension; + use CreateSqsQueueTrait; /** - * {@inheritdoc} + * @var SqsContext */ - protected function createContext() + private $context; + + protected function tearDown() + { + parent::tearDown(); + + if ($this->context && $this->queue) { + $this->context->deleteQueue($this->queue); + } + } + + protected function createContext(): SqsContext + { + return $this->context = $this->buildSqsContext(); + } + + protected function createQueue(Context $context, $queueName): SqsDestination { - throw new \LogicException('Should not be ever called'); + return $this->createSqsQueue($context, $queueName); } } diff --git a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromTopicTest.php b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromTopicTest.php index 3d9149b05..a813fdb6f 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromTopicTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToAndReceiveNoWaitFromTopicTest.php @@ -2,6 +2,10 @@ namespace Enqueue\Sqs\Tests\Spec; +use Enqueue\Sqs\SqsContext; +use Enqueue\Sqs\SqsDestination; +use Enqueue\Test\SqsExtension; +use Interop\Queue\Context; use Interop\Queue\Spec\SendToAndReceiveNoWaitFromTopicSpec; /** @@ -9,16 +13,30 @@ */ class SqsSendToAndReceiveNoWaitFromTopicTest extends SendToAndReceiveNoWaitFromTopicSpec { - public function test() - { - $this->markTestSkipped('The test is fragile. This is how SQS.'); - } + use SqsExtension; + use CreateSqsQueueTrait; /** - * {@inheritdoc} + * @var SqsContext */ - protected function createContext() + private $context; + + protected function tearDown() + { + parent::tearDown(); + + if ($this->context && $this->queue) { + $this->context->deleteQueue($this->queue); + } + } + + protected function createContext(): SqsContext + { + return $this->context = $this->buildSqsContext(); + } + + protected function createTopic(Context $context, $queueName): SqsDestination { - throw new \LogicException('Should not be ever called'); + return $this->createSqsQueue($context, $queueName); } } diff --git a/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveFromQueueTest.php b/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveFromQueueTest.php index a9db45362..082fa527a 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveFromQueueTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveFromQueueTest.php @@ -2,6 +2,10 @@ namespace Enqueue\Sqs\Tests\Spec; +use Enqueue\Sqs\SqsContext; +use Enqueue\Sqs\SqsDestination; +use Enqueue\Test\SqsExtension; +use Interop\Queue\Context; use Interop\Queue\Spec\SendToTopicAndReceiveFromQueueSpec; /** @@ -9,16 +13,35 @@ */ class SqsSendToTopicAndReceiveFromQueueTest extends SendToTopicAndReceiveFromQueueSpec { - public function test() - { - $this->markTestSkipped('The SQS does not support it'); - } + use SqsExtension; + use CreateSqsQueueTrait; /** - * {@inheritdoc} + * @var SqsContext */ - protected function createContext() + private $context; + + protected function tearDown() + { + parent::tearDown(); + + if ($this->context && $this->queue) { + $this->context->deleteQueue($this->queue); + } + } + + protected function createContext(): SqsContext + { + return $this->context = $this->buildSqsContext(); + } + + protected function createTopic(Context $context, $queueName): SqsDestination + { + return $this->createSqsQueue($context, $queueName); + } + + protected function createQueue(Context $context, $queueName): SqsDestination { - throw new \LogicException('Should not be ever called'); + return $this->createSqsQueue($context, $queueName); } } diff --git a/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveNoWaitFromQueueTest.php b/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveNoWaitFromQueueTest.php index bbb9be63a..d4175ef4e 100644 --- a/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveNoWaitFromQueueTest.php +++ b/pkg/sqs/Tests/Spec/SqsSendToTopicAndReceiveNoWaitFromQueueTest.php @@ -2,6 +2,10 @@ namespace Enqueue\Sqs\Tests\Spec; +use Enqueue\Sqs\SqsContext; +use Enqueue\Sqs\SqsDestination; +use Enqueue\Test\SqsExtension; +use Interop\Queue\Context; use Interop\Queue\Spec\SendToTopicAndReceiveNoWaitFromQueueSpec; /** @@ -9,16 +13,35 @@ */ class SqsSendToTopicAndReceiveNoWaitFromQueueTest extends SendToTopicAndReceiveNoWaitFromQueueSpec { - public function test() - { - $this->markTestSkipped('The SQS does not support it'); - } + use SqsExtension; + use CreateSqsQueueTrait; /** - * {@inheritdoc} + * @var SqsContext */ - protected function createContext() + private $context; + + protected function tearDown() + { + parent::tearDown(); + + if ($this->context && $this->queue) { + $this->context->deleteQueue($this->queue); + } + } + + protected function createContext(): SqsContext + { + return $this->context = $this->buildSqsContext(); + } + + protected function createTopic(Context $context, $queueName): SqsDestination + { + return $this->createSqsQueue($context, $queueName); + } + + protected function createQueue(Context $context, $queueName): SqsDestination { - throw new \LogicException('Should not be ever called'); + return $this->createSqsQueue($context, $queueName); } } diff --git a/pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php b/pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php index f2ad15948..375b0d03a 100644 --- a/pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php +++ b/pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php @@ -63,6 +63,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => true, 'endpoint' => null, + 'queue_owner_aws_account_id' => null, ], ]; @@ -77,6 +78,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => true, 'endpoint' => null, + 'queue_owner_aws_account_id' => null, ], ]; @@ -91,6 +93,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => true, 'endpoint' => null, + 'queue_owner_aws_account_id' => null, ], ]; @@ -105,6 +108,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => false, 'endpoint' => null, + 'queue_owner_aws_account_id' => null, ], ]; @@ -119,6 +123,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => false, 'endpoint' => null, + 'queue_owner_aws_account_id' => null, ], ]; @@ -133,6 +138,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => false, 'endpoint' => null, + 'queue_owner_aws_account_id' => null, ], ]; @@ -153,6 +159,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => false, 'endpoint' => 'http://localstack:1111', + 'queue_owner_aws_account_id' => null, ], ]; } diff --git a/pkg/sqs/Tests/SqsConnectionFactoryTest.php b/pkg/sqs/Tests/SqsConnectionFactoryTest.php index c4544c9e0..21d3784c4 100644 --- a/pkg/sqs/Tests/SqsConnectionFactoryTest.php +++ b/pkg/sqs/Tests/SqsConnectionFactoryTest.php @@ -7,8 +7,9 @@ use Enqueue\Sqs\SqsContext; use Enqueue\Test\ClassExtensionTrait; use Interop\Queue\ConnectionFactory; +use PHPUnit\Framework\TestCase; -class SqsConnectionFactoryTest extends \PHPUnit\Framework\TestCase +class SqsConnectionFactoryTest extends TestCase { use ClassExtensionTrait; @@ -30,6 +31,7 @@ public function testCouldBeConstructedWithEmptyConfiguration() 'retries' => 3, 'version' => '2012-11-05', 'endpoint' => null, + 'queue_owner_aws_account_id' => null, ], 'config', $factory); } @@ -46,6 +48,7 @@ public function testCouldBeConstructedWithCustomConfiguration() 'retries' => 3, 'version' => '2012-11-05', 'endpoint' => null, + 'queue_owner_aws_account_id' => null, ], 'config', $factory); } diff --git a/pkg/sqs/Tests/SqsContextTest.php b/pkg/sqs/Tests/SqsContextTest.php index f6567d870..9ed8e40c7 100644 --- a/pkg/sqs/Tests/SqsContextTest.php +++ b/pkg/sqs/Tests/SqsContextTest.php @@ -26,26 +26,26 @@ public function testShouldImplementContextInterface() public function testCouldBeConstructedWithSqsClientAsFirstArgument() { - new SqsContext($this->createSqsClientMock()); + new SqsContext($this->createSqsClientMock(), []); } public function testCouldBeConstructedWithSqsClientFactoryAsFirstArgument() { new SqsContext(function () { return $this->createSqsClientMock(); - }); + }, []); } public function testThrowIfNeitherSqsClientNorFactoryGiven() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The $client argument must be either Aws\Sqs\SqsClient or callable that returns Aws\Sqs\SqsClient once called.'); - new SqsContext(new \stdClass()); + new SqsContext(new \stdClass(), []); } public function testShouldAllowCreateEmptyMessage() { - $context = new SqsContext($this->createSqsClientMock()); + $context = new SqsContext($this->createSqsClientMock(), []); $message = $context->createMessage(); @@ -58,7 +58,7 @@ public function testShouldAllowCreateEmptyMessage() public function testShouldAllowCreateCustomMessage() { - $context = new SqsContext($this->createSqsClientMock()); + $context = new SqsContext($this->createSqsClientMock(), []); $message = $context->createMessage('theBody', ['aProp' => 'aPropVal'], ['aHeader' => 'aHeaderVal']); @@ -71,7 +71,9 @@ public function testShouldAllowCreateCustomMessage() public function testShouldCreateQueue() { - $context = new SqsContext($this->createSqsClientMock()); + $context = new SqsContext($this->createSqsClientMock(), [ + 'queue_owner_aws_account_id' => null, + ]); $queue = $context->createQueue('aQueue'); @@ -81,7 +83,9 @@ public function testShouldCreateQueue() public function testShouldAllowCreateTopic() { - $context = new SqsContext($this->createSqsClientMock()); + $context = new SqsContext($this->createSqsClientMock(), [ + 'queue_owner_aws_account_id' => null, + ]); $topic = $context->createTopic('aTopic'); @@ -91,7 +95,7 @@ public function testShouldAllowCreateTopic() public function testThrowNotImplementedOnCreateTmpQueueCall() { - $context = new SqsContext($this->createSqsClientMock()); + $context = new SqsContext($this->createSqsClientMock(), []); $this->expectException(TemporaryQueueNotSupportedException::class); @@ -100,7 +104,7 @@ public function testThrowNotImplementedOnCreateTmpQueueCall() public function testShouldCreateProducer() { - $context = new SqsContext($this->createSqsClientMock()); + $context = new SqsContext($this->createSqsClientMock(), []); $producer = $context->createProducer(); @@ -109,7 +113,7 @@ public function testShouldCreateProducer() public function testShouldThrowIfNotSqsDestinationGivenOnCreateConsumer() { - $context = new SqsContext($this->createSqsClientMock()); + $context = new SqsContext($this->createSqsClientMock(), []); $this->expectException(InvalidDestinationException::class); $this->expectExceptionMessage('The destination must be an instance of Enqueue\Sqs\SqsDestination but got Mock_Queue'); @@ -119,7 +123,9 @@ public function testShouldThrowIfNotSqsDestinationGivenOnCreateConsumer() public function testShouldCreateConsumer() { - $context = new SqsContext($this->createSqsClientMock()); + $context = new SqsContext($this->createSqsClientMock(), [ + 'queue_owner_aws_account_id' => null, + ]); $queue = $context->createQueue('aQueue'); @@ -138,7 +144,9 @@ public function testShouldAllowDeclareQueue() ->willReturn(new Result(['QueueUrl' => 'theQueueUrl'])) ; - $context = new SqsContext($sqsClient); + $context = new SqsContext($sqsClient, [ + 'queue_owner_aws_account_id' => null, + ]); $queue = $context->createQueue('aQueueName'); @@ -161,7 +169,9 @@ public function testShouldAllowDeleteQueue() ->willReturn(new Result()) ; - $context = new SqsContext($sqsClient); + $context = new SqsContext($sqsClient, [ + 'queue_owner_aws_account_id' => null, + ]); $queue = $context->createQueue('aQueueName'); @@ -184,7 +194,9 @@ public function testShouldAllowPurgeQueue() ->willReturn(new Result()) ; - $context = new SqsContext($sqsClient); + $context = new SqsContext($sqsClient, [ + 'queue_owner_aws_account_id' => null, + ]); $queue = $context->createQueue('aQueueName'); @@ -201,7 +213,29 @@ public function testShouldAllowGetQueueUrl() ->willReturn(new Result(['QueueUrl' => 'theQueueUrl'])) ; - $context = new SqsContext($sqsClient); + $context = new SqsContext($sqsClient, [ + 'queue_owner_aws_account_id' => null, + ]); + + $context->getQueueUrl(new SqsDestination('aQueueName')); + } + + public function testShouldAllowGetQueueUrlFromAnotherAWSAccount() + { + $sqsClient = $this->createSqsClientMock(); + $sqsClient + ->expects($this->once()) + ->method('getQueueUrl') + ->with($this->identicalTo([ + 'QueueName' => 'aQueueName', + 'QueueOwnerAWSAccountId' => 'anotherAWSAccountID', + ])) + ->willReturn(new Result(['QueueUrl' => 'theQueueUrl'])) + ; + + $context = new SqsContext($sqsClient, [ + 'queue_owner_aws_account_id' => 'anotherAWSAccountID', + ]); $context->getQueueUrl(new SqsDestination('aQueueName')); } @@ -216,7 +250,9 @@ public function testShouldThrowExceptionIfGetQueueUrlResultHasNoQueueUrlProperty ->willReturn(new Result([])) ; - $context = new SqsContext($sqsClient); + $context = new SqsContext($sqsClient, [ + 'queue_owner_aws_account_id' => null, + ]); $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('QueueUrl cannot be resolved. queueName: "aQueueName"');