From 6b74de53879e52fbbc1005a23f57c7e8e9fa65be Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 Jan 2024 14:51:25 +0100 Subject: [PATCH 1/2] Apply php-cs-fixer fix --rules nullable_type_declaration_for_default_null_value --- Tests/Transport/AmazonSqsTransportTest.php | 4 ++-- Transport/AmazonSqsFifoStamp.php | 2 +- Transport/AmazonSqsReceiver.php | 2 +- Transport/AmazonSqsTransport.php | 2 +- Transport/AmazonSqsTransportFactory.php | 2 +- Transport/Connection.php | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Tests/Transport/AmazonSqsTransportTest.php b/Tests/Transport/AmazonSqsTransportTest.php index 8e7b152..303f8e4 100644 --- a/Tests/Transport/AmazonSqsTransportTest.php +++ b/Tests/Transport/AmazonSqsTransportTest.php @@ -167,7 +167,7 @@ public function testItConvertsHttpExceptionDuringResetIntoTransportException() $this->transport->reset(); } - private function getTransport(SerializerInterface $serializer = null, Connection $connection = null) + private function getTransport(?SerializerInterface $serializer = null, ?Connection $connection = null) { $serializer = $serializer ?? $this->createMock(SerializerInterface::class); $connection = $connection ?? $this->createMock(Connection::class); @@ -178,7 +178,7 @@ private function getTransport(SerializerInterface $serializer = null, Connection private function createHttpException(): HttpException { $response = $this->createMock(ResponseInterface::class); - $response->method('getInfo')->willReturnCallback(static function (string $type = null) { + $response->method('getInfo')->willReturnCallback(static function (?string $type = null) { $info = [ 'http_code' => 500, 'url' => 'https://symfony.com', diff --git a/Transport/AmazonSqsFifoStamp.php b/Transport/AmazonSqsFifoStamp.php index 997ac45..4383c04 100644 --- a/Transport/AmazonSqsFifoStamp.php +++ b/Transport/AmazonSqsFifoStamp.php @@ -18,7 +18,7 @@ final class AmazonSqsFifoStamp implements NonSendableStampInterface private $messageGroupId; private $messageDeduplicationId; - public function __construct(string $messageGroupId = null, string $messageDeduplicationId = null) + public function __construct(?string $messageGroupId = null, ?string $messageDeduplicationId = null) { $this->messageGroupId = $messageGroupId; $this->messageDeduplicationId = $messageDeduplicationId; diff --git a/Transport/AmazonSqsReceiver.php b/Transport/AmazonSqsReceiver.php index 89dcf06..44d9843 100644 --- a/Transport/AmazonSqsReceiver.php +++ b/Transport/AmazonSqsReceiver.php @@ -29,7 +29,7 @@ class AmazonSqsReceiver implements ReceiverInterface, MessageCountAwareInterface private $connection; private $serializer; - public function __construct(Connection $connection, SerializerInterface $serializer = null) + public function __construct(Connection $connection, ?SerializerInterface $serializer = null) { $this->connection = $connection; $this->serializer = $serializer ?? new PhpSerializer(); diff --git a/Transport/AmazonSqsTransport.php b/Transport/AmazonSqsTransport.php index 50c7b8f..35a6334 100644 --- a/Transport/AmazonSqsTransport.php +++ b/Transport/AmazonSqsTransport.php @@ -33,7 +33,7 @@ class AmazonSqsTransport implements TransportInterface, SetupableTransportInterf private $receiver; private $sender; - public function __construct(Connection $connection, SerializerInterface $serializer = null, ReceiverInterface $receiver = null, SenderInterface $sender = null) + public function __construct(Connection $connection, ?SerializerInterface $serializer = null, ?ReceiverInterface $receiver = null, ?SenderInterface $sender = null) { $this->connection = $connection; $this->serializer = $serializer ?? new PhpSerializer(); diff --git a/Transport/AmazonSqsTransportFactory.php b/Transport/AmazonSqsTransportFactory.php index 0673966..88959a3 100644 --- a/Transport/AmazonSqsTransportFactory.php +++ b/Transport/AmazonSqsTransportFactory.php @@ -23,7 +23,7 @@ class AmazonSqsTransportFactory implements TransportFactoryInterface { private $logger; - public function __construct(LoggerInterface $logger = null) + public function __construct(?LoggerInterface $logger = null) { $this->logger = $logger; } diff --git a/Transport/Connection.php b/Transport/Connection.php index fc802db..dba0514 100644 --- a/Transport/Connection.php +++ b/Transport/Connection.php @@ -60,7 +60,7 @@ class Connection /** @var string|null */ private $queueUrl; - public function __construct(array $configuration, SqsClient $client = null, string $queueUrl = null) + public function __construct(array $configuration, ?SqsClient $client = null, ?string $queueUrl = null) { $this->configuration = array_replace_recursive(self::DEFAULT_OPTIONS, $configuration); $this->client = $client ?? new SqsClient([]); @@ -101,7 +101,7 @@ public function __destruct() * * auto_setup: Whether the queue should be created automatically during send / get (Default: true) * * debug: Log all HTTP requests and responses as LoggerInterface::DEBUG (Default: false) */ - public static function fromDsn(string $dsn, array $options = [], HttpClientInterface $client = null, LoggerInterface $logger = null): self + public static function fromDsn(string $dsn, array $options = [], ?HttpClientInterface $client = null, ?LoggerInterface $logger = null): self { if (false === $params = parse_url($dsn)) { throw new InvalidArgumentException('The given Amazon SQS DSN is invalid.'); @@ -313,7 +313,7 @@ public function getMessageCount(): int return (int) ($attributes[QueueAttributeName::APPROXIMATE_NUMBER_OF_MESSAGES] ?? 0); } - public function send(string $body, array $headers, int $delay = 0, string $messageGroupId = null, string $messageDeduplicationId = null, string $xrayTraceId = null): void + public function send(string $body, array $headers, int $delay = 0, ?string $messageGroupId = null, ?string $messageDeduplicationId = null, ?string $xrayTraceId = null): void { if ($this->configuration['auto_setup']) { $this->setup(); From 9598344d3d095afe2d5d10f644a0c367c04c1789 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 Jan 2024 14:37:48 +0100 Subject: [PATCH 2/2] minor #53524 [Messenger] [AmazonSqs] Allow `async-aws/sqs` version 2 (smoench) This PR was merged into the 5.4 branch. Discussion ---------- [Messenger] [AmazonSqs] Allow `async-aws/sqs` version 2 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT With this PR async-aws/sqs version 2 would be allowed to be installed. [With version 2 they are using the AWS JSON-1.0 protocol instead of the XML one](https://github.com/async-aws/sqs/blob/master/CHANGELOG.md#200). They declared this as a BC-Break as they switced the protocol from query to json, but no public method signatures have been changed. TODO - [x] Provide JSON stubs for tests Commits ------- 96f103aef2 [Messenger][AmazonSqs] Allow async-aws/sqs version 2 --- Tests/Transport/ConnectionTest.php | 40 ++++++++++++++++++++++++++++++ composer.json | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Tests/Transport/ConnectionTest.php b/Tests/Transport/ConnectionTest.php index 4a24465..691b3fd 100644 --- a/Tests/Transport/ConnectionTest.php +++ b/Tests/Transport/ConnectionTest.php @@ -17,6 +17,7 @@ use AsyncAws\Sqs\Result\ReceiveMessageResult; use AsyncAws\Sqs\SqsClient; use AsyncAws\Sqs\ValueObject\Message; +use Composer\InstalledVersions; use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; use Symfony\Component\HttpClient\MockHttpClient; @@ -358,6 +359,16 @@ public function testLoggerWithDebugOption() private function getMockedQueueUrlResponse(): MockResponse { + if ($this->isAsyncAwsSqsVersion2Installed()) { + return new MockResponse( + << @@ -373,6 +384,28 @@ private function getMockedQueueUrlResponse(): MockResponse private function getMockedReceiveMessageResponse(): MockResponse { + if ($this->isAsyncAwsSqsVersion2Installed()) { + return new MockResponse(<<=8.1", "async-aws/core": "^1.5", - "async-aws/sqs": "^1.0", + "async-aws/sqs": "^1.0|^2.0", "symfony/messenger": "^5.4|^6.0", "symfony/service-contracts": "^2.5|^3", "psr/log": "^1|^2|^3"