Skip to content

Commit

Permalink
More cleanups and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jan 27, 2021
1 parent 3edc0b6 commit a75e345
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Tests/Transport/AmazonSqsReceiverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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');

Expand Down
12 changes: 4 additions & 8 deletions Tests/Transport/AmazonSqsSenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Tests/Transport/AmazonSqsTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -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);
}
Expand Down
24 changes: 12 additions & 12 deletions Tests/Transport/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)),
Expand All @@ -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)),
Expand Down

0 comments on commit a75e345

Please sign in to comment.