Repository navigation
Expand file tree
/
Copy pathFsMessageTest.php
More file actions
108 lines (79 loc) · 3.19 KB
/
Copy pathFsMessageTest.php
File metadata and controls
108 lines (79 loc) · 3.19 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
<?php
namespace Enqueue\Fs\Tests;
use Enqueue\Fs\FsMessage;
use Enqueue\Test\ClassExtensionTrait;
class FsMessageTest extends \PHPUnit\Framework\TestCase
{
use ClassExtensionTrait;
public function testShouldImplementJsonSerializableInterface()
{
$this->assertClassImplements(\JsonSerializable::class, FsMessage::class);
}
public function testCouldConstructMessageWithoutArguments()
{
$message = new FsMessage('');
$this->assertSame('', $message->getBody());
$this->assertSame([], $message->getHeaders());
$this->assertSame([], $message->getProperties());
}
public function testCouldConstructMessageWithBody()
{
$message = new FsMessage('body');
$this->assertSame('body', $message->getBody());
}
public function testCouldConstructMessageWithProperties()
{
$message = new FsMessage('', ['key' => 'value']);
$this->assertSame(['key' => 'value'], $message->getProperties());
}
public function testCouldConstructMessageWithHeaders()
{
$message = new FsMessage('', [], ['key' => 'value']);
$this->assertSame(['key' => 'value'], $message->getHeaders());
}
public function testShouldSetCorrelationIdAsHeader()
{
$message = new FsMessage();
$message->setCorrelationId('the-correlation-id');
$this->assertSame(['correlation_id' => 'the-correlation-id'], $message->getHeaders());
}
public function testCouldSetMessageIdAsHeader()
{
$message = new FsMessage();
$message->setMessageId('the-message-id');
$this->assertSame(['message_id' => 'the-message-id'], $message->getHeaders());
}
public function testCouldSetTimestampAsHeader()
{
$message = new FsMessage();
$message->setTimestamp(12345);
$this->assertSame(['timestamp' => 12345], $message->getHeaders());
}
public function testShouldAllowGetPreviouslySetReplyToAsHeader()
{
$message = new FsMessage();
$message->setReplyTo('theQueueName');
$this->assertSame(['reply_to' => 'theQueueName'], $message->getHeaders());
}
public function testColdBeSerializedToJson()
{
$message = new FsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal']);
$this->assertEquals('{"body":"theBody","properties":{"thePropFoo":"thePropFooVal"},"headers":{"theHeaderFoo":"theHeaderFooVal"}}', json_encode($message));
}
public function testCouldBeUnserializedFromJson()
{
$message = new FsMessage('theBody', ['thePropFoo' => 'thePropFooVal'], ['theHeaderFoo' => 'theHeaderFooVal']);
$json = json_encode($message);
//guard
$this->assertNotEmpty($json);
$unserializedMessage = FsMessage::jsonUnserialize($json);
$this->assertInstanceOf(FsMessage::class, $unserializedMessage);
$this->assertEquals($message, $unserializedMessage);
}
public function testThrowIfMalformedJsonGivenOnUnsterilizedFromJson()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The malformed json given.');
FsMessage::jsonUnserialize('{]');
}
}