-
Notifications
You must be signed in to change notification settings - Fork 435
Expand file tree
/
Copy pathSqsMessageTest.php
More file actions
125 lines (96 loc) · 3.72 KB
/
SqsMessageTest.php
File metadata and controls
125 lines (96 loc) · 3.72 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace Enqueue\Sqs\Tests;
use Enqueue\Sqs\SqsMessage;
use Enqueue\Test\ClassExtensionTrait;
class SqsMessageTest extends \PHPUnit\Framework\TestCase
{
use ClassExtensionTrait;
public function testCouldBeConstructedWithoutArguments()
{
$message = new SqsMessage();
$this->assertSame('', $message->getBody());
$this->assertSame([], $message->getProperties());
$this->assertSame([], $message->getHeaders());
$this->assertSame([], $message->getAttributes());
}
public function testCouldBeConstructedWithOptionalArguments()
{
$message = new SqsMessage('theBody', ['barProp' => 'barPropVal'], ['fooHeader' => 'fooHeaderVal']);
$this->assertSame('theBody', $message->getBody());
$this->assertSame(['barProp' => 'barPropVal'], $message->getProperties());
$this->assertSame(['fooHeader' => 'fooHeaderVal'], $message->getHeaders());
}
public function testShouldSetCorrelationIdAsHeader()
{
$message = new SqsMessage();
$message->setCorrelationId('the-correlation-id');
$this->assertSame(['correlation_id' => 'the-correlation-id'], $message->getHeaders());
}
public function testShouldSetMessageIdAsHeader()
{
$message = new SqsMessage();
$message->setMessageId('the-message-id');
$this->assertSame(['message_id' => 'the-message-id'], $message->getHeaders());
}
public function testShouldSetTimestampAsHeader()
{
$message = new SqsMessage();
$message->setTimestamp(12345);
$this->assertSame(['timestamp' => 12345], $message->getHeaders());
}
public function testShouldGetTimestampFromSentTimestampAttribute()
{
$message = new SqsMessage();
$message->setAttributes([
'SentTimestamp' => '1560512260079',
]);
$this->assertSame(1560512260, $message->getTimestamp());
}
public function testShouldReturnNullTimestampWhenSentTimestampAttributeIsMissing()
{
$message = new SqsMessage();
$this->assertNull($message->getTimestamp());
}
public function testShouldSetReplyToAsHeader()
{
$message = new SqsMessage();
$message->setReplyTo('theQueueName');
$this->assertSame(['reply_to' => 'theQueueName'], $message->getHeaders());
}
public function testShouldAllowGetDelaySeconds()
{
$message = new SqsMessage();
$message->setDelaySeconds(12345);
$this->assertSame(12345, $message->getDelaySeconds());
}
public function testShouldAllowGetMessageDeduplicationId()
{
$message = new SqsMessage();
$message->setMessageDeduplicationId('theId');
$this->assertSame('theId', $message->getMessageDeduplicationId());
}
public function testShouldAllowGetMessageGroupId()
{
$message = new SqsMessage();
$message->setMessageGroupId('theId');
$this->assertSame('theId', $message->getMessageGroupId());
}
public function testShouldAllowGetReceiptHandle()
{
$message = new SqsMessage();
$message->setReceiptHandle('theId');
$this->assertSame('theId', $message->getReceiptHandle());
}
public function testShouldAllowSettingAndGettingAttributes()
{
$message = new SqsMessage();
$message->setAttributes($attributes = [
'SenderId' => 'AROAX5IAWYILCTYIS3OZ5:foo@bar.com',
'ApproximateFirstReceiveTimestamp' => '1560512269481',
'ApproximateReceiveCount' => '2',
'SentTimestamp' => '1560512260079',
]);
$this->assertSame($attributes, $message->getAttributes());
$this->assertSame($attributes['SenderId'], $message->getAttribute('SenderId'));
}
}