File: SendMessageBatchResultTest.php

package info (click to toggle)
php-async-aws-sqs 2.7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 664 kB
  • sloc: php: 4,040; makefile: 31
file content (50 lines) | stat: -rw-r--r-- 2,100 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php

namespace AsyncAws\Sqs\Tests\Unit\Result;

use AsyncAws\Core\Response;
use AsyncAws\Core\Test\Http\SimpleMockedResponse;
use AsyncAws\Core\Test\TestCase;
use AsyncAws\Sqs\Result\SendMessageBatchResult;
use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;

class SendMessageBatchResultTest extends TestCase
{
    public function testSendMessageBatchResult(): void
    {
        // see https://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_SendMessageBatch.html
        $response = new SimpleMockedResponse(<<<JSON
{
   "Failed": [],
    "Successful": [
        {
            "Id": "test_msg_001",
            "MD5OfMessageBody": "0e024d309850c78cba5eabbeff7cae71",
            "MessageId": "0a5231c7-8bff-4955-be2e-8dc7c50a25fa"
        },
        {
            "Id": "test_msg_002",
            "MD5OfMessageAttributes": "295c5fa15a51aae6884d1d7c1d99ca50",
            "MD5OfMessageBody": "7fb8146a82f95e0af155278f406862c2",
            "MessageId": "15ee1ed3-87e7-40c1-bdaa-2e49968ea7e9"
        }
    ]
}
JSON
        );

        $client = new MockHttpClient($response);
        $result = new SendMessageBatchResult(new Response($client->request('POST', 'http://localhost'), $client, new NullLogger()));

        self::assertCount(2, $result->getSuccessful());
        self::assertSame('test_msg_001', $result->getSuccessful()[0]->getId());
        self::assertSame('0a5231c7-8bff-4955-be2e-8dc7c50a25fa', $result->getSuccessful()[0]->getMessageId());
        self::assertSame('0e024d309850c78cba5eabbeff7cae71', $result->getSuccessful()[0]->getMd5OfMessageBody());
        self::assertSame('test_msg_002', $result->getSuccessful()[1]->getId());
        self::assertSame('15ee1ed3-87e7-40c1-bdaa-2e49968ea7e9', $result->getSuccessful()[1]->getMessageId());
        self::assertSame('7fb8146a82f95e0af155278f406862c2', $result->getSuccessful()[1]->getMd5OfMessageBody());
        self::assertSame('295c5fa15a51aae6884d1d7c1d99ca50', $result->getSuccessful()[1]->getMd5OfMessageAttributes());
        self::assertCount(0, $result->getFailed());
    }
}