From a75e34556edc5a85adc8e67a9a521d2c1fbc90a0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 27 Jan 2021 12:17:55 +0100 Subject: [PATCH] More cleanups and fixes --- Tests/Transport/AmazonSqsReceiverTest.php | 4 ++-- Tests/Transport/AmazonSqsSenderTest.php | 12 ++++------- Tests/Transport/AmazonSqsTransportTest.php | 8 ++++---- Tests/Transport/ConnectionTest.php | 24 +++++++++++----------- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Tests/Transport/AmazonSqsReceiverTest.php b/Tests/Transport/AmazonSqsReceiverTest.php index b624dcb..96cf25f 100644 --- a/Tests/Transport/AmazonSqsReceiverTest.php +++ b/Tests/Transport/AmazonSqsReceiverTest.php @@ -29,7 +29,7 @@ public function testItReturnsTheDecodedMessageToTheHandler() $serializer = $this->createSerializer(); $sqsEnvelop = $this->createSqsEnvelope(); - $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); + $connection = $this->createMock(Connection::class); $connection->method('get')->willReturn($sqsEnvelop); $receiver = new AmazonSqsReceiver($connection, $serializer); @@ -46,7 +46,7 @@ public function testItRejectTheMessageIfThereIsAMessageDecodingFailedException() $serializer->method('decode')->willThrowException(new MessageDecodingFailedException()); $sqsEnvelop = $this->createSqsEnvelope(); - $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); + $connection = $this->createMock(Connection::class); $connection->method('get')->willReturn($sqsEnvelop); $connection->expects($this->once())->method('delete'); diff --git a/Tests/Transport/AmazonSqsSenderTest.php b/Tests/Transport/AmazonSqsSenderTest.php index 412faf0..3c94764 100644 --- a/Tests/Transport/AmazonSqsSenderTest.php +++ b/Tests/Transport/AmazonSqsSenderTest.php @@ -26,12 +26,10 @@ public function testSend(): void $envelope = new Envelope(new DummyMessage('Oy')); $encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]]; - $connection = $this->getMockBuilder(Connection::class) - ->disableOriginalConstructor() - ->getMock(); + $connection = $this->createMock(Connection::class); $connection->expects($this->once())->method('send')->with($encoded['body'], $encoded['headers']); - $serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(); + $serializer = $this->createMock(SerializerInterface::class); $serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded); $sender = new AmazonSqsSender($connection, $serializer); @@ -45,13 +43,11 @@ public function testSendWithAmazonSqsFifoStamp(): void $encoded = ['body' => '...', 'headers' => ['type' => DummyMessage::class]]; - $connection = $this->getMockBuilder(Connection::class) - ->disableOriginalConstructor() - ->getMock(); + $connection = $this->createMock(Connection::class); $connection->expects($this->once())->method('send') ->with($encoded['body'], $encoded['headers'], 0, $stamp->getMessageGroupId(), $stamp->getMessageDeduplicationId()); - $serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(); + $serializer = $this->createMock(SerializerInterface::class); $serializer->method('encode')->with($envelope)->willReturnOnConsecutiveCalls($encoded); $sender = new AmazonSqsSender($connection, $serializer); diff --git a/Tests/Transport/AmazonSqsTransportTest.php b/Tests/Transport/AmazonSqsTransportTest.php index 9e64305..1282de3 100644 --- a/Tests/Transport/AmazonSqsTransportTest.php +++ b/Tests/Transport/AmazonSqsTransportTest.php @@ -31,8 +31,8 @@ public function testItIsATransport() public function testReceivesMessages() { $transport = $this->getTransport( - $serializer = $this->getMockBuilder(SerializerInterface::class)->getMock(), - $connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock() + $serializer = $this->createMock(SerializerInterface::class), + $connection = $this->createMock(Connection::class) ); $decodedMessage = new DummyMessage('Decoded.'); @@ -52,8 +52,8 @@ public function testReceivesMessages() private function getTransport(SerializerInterface $serializer = null, Connection $connection = null) { - $serializer = $serializer ?: $this->getMockBuilder(SerializerInterface::class)->getMock(); - $connection = $connection ?: $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); + $serializer = $serializer ?: $this->createMock(SerializerInterface::class); + $connection = $connection ?: $this->createMock(Connection::class); return new AmazonSqsTransport($connection, $serializer); } diff --git a/Tests/Transport/ConnectionTest.php b/Tests/Transport/ConnectionTest.php index eda709d..4cf5623 100644 --- a/Tests/Transport/ConnectionTest.php +++ b/Tests/Transport/ConnectionTest.php @@ -42,7 +42,7 @@ public function testConfigureWithCredentials() $awsKey = 'some_aws_access_key_value'; $awsSecret = 'some_aws_secret_value'; $region = 'eu-west-1'; - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['queue_name' => 'queue'], new SqsClient(['region' => $region, 'accessKeyId' => $awsKey, 'accessKeySecret' => $awsSecret], null, $httpClient)), Connection::fromDsn('sqs://default/queue', [ @@ -63,7 +63,7 @@ public function testFromInvalidDsn() public function testFromDsn() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), Connection::fromDsn('sqs://default/queue', [], $httpClient) @@ -72,7 +72,7 @@ public function testFromDsn() public function testDsnPrecedence() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['queue_name' => 'queue_dsn'], new SqsClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $httpClient)), 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) @@ -81,7 +81,7 @@ public function testDsnPrecedence() public function testFromDsnWithRegion() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'us-west-2', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), Connection::fromDsn('sqs://default/queue?region=us-west-2', [], $httpClient) @@ -90,7 +90,7 @@ public function testFromDsnWithRegion() public function testFromDsnWithCustomEndpoint() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'endpoint' => 'https://localhost', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), Connection::fromDsn('sqs://localhost/queue', [], $httpClient) @@ -99,7 +99,7 @@ public function testFromDsnWithCustomEndpoint() public function testFromDsnWithSslMode() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'endpoint' => 'http://localhost', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), Connection::fromDsn('sqs://localhost/queue?sslmode=disable', [], $httpClient) @@ -108,7 +108,7 @@ public function testFromDsnWithSslMode() public function testFromDsnWithSslModeOnDefault() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), Connection::fromDsn('sqs://default/queue?sslmode=disable', [], $httpClient) @@ -117,7 +117,7 @@ public function testFromDsnWithSslModeOnDefault() public function testFromDsnWithCustomEndpointAndPort() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'endpoint' => 'https://localhost:1234', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), Connection::fromDsn('sqs://localhost:1234/queue', [], $httpClient) @@ -126,7 +126,7 @@ public function testFromDsnWithCustomEndpointAndPort() public function testFromDsnWithOptions() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['account' => '213', 'queue_name' => 'queue', 'buffer_size' => 1, 'wait_time' => 5, 'auto_setup' => false], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), Connection::fromDsn('sqs://default/213/queue', ['buffer_size' => 1, 'wait_time' => 5, 'auto_setup' => false], $httpClient) @@ -135,7 +135,7 @@ public function testFromDsnWithOptions() public function testFromDsnWithQueryOptions() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['account' => '213', 'queue_name' => 'queue', 'buffer_size' => 1, 'wait_time' => 5, 'auto_setup' => false], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), Connection::fromDsn('sqs://default/213/queue?buffer_size=1&wait_time=5&auto_setup=0', [], $httpClient) @@ -144,7 +144,7 @@ public function testFromDsnWithQueryOptions() public function testFromDsnWithQueueNameOption() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['queue_name' => 'queue'], new SqsClient(['region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)), @@ -159,7 +159,7 @@ public function testFromDsnWithQueueNameOption() public function testFromDsnWithAccountAndEndpointOption() { - $httpClient = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $httpClient = $this->createMock(HttpClientInterface::class); $this->assertEquals( new Connection(['account' => 12345], new SqsClient(['endpoint' => 'https://custom-endpoint.tld', 'region' => 'eu-west-1', 'accessKeyId' => null, 'accessKeySecret' => null], null, $httpClient)),