Repository navigation
Expand file tree
/
Copy pathStompProducerTest.php
More file actions
109 lines (87 loc) · 3.32 KB
/
Copy pathStompProducerTest.php
File metadata and controls
109 lines (87 loc) · 3.32 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
<?php
namespace Enqueue\Stomp\Tests;
use Enqueue\Stomp\StompDestination;
use Enqueue\Stomp\StompMessage;
use Enqueue\Stomp\StompProducer;
use Enqueue\Test\ClassExtensionTrait;
use Interop\Queue\InvalidDestinationException;
use Interop\Queue\InvalidMessageException;
use Interop\Queue\PsrMessage;
use Interop\Queue\PsrProducer;
use Interop\Queue\PsrQueue;
use Stomp\Client;
use Stomp\Transport\Message;
class StompProducerTest extends \PHPUnit\Framework\TestCase
{
use ClassExtensionTrait;
public function testShouldImplementProducerInterface()
{
$this->assertClassImplements(PsrProducer::class, StompProducer::class);
}
public function testShouldThrowInvalidDestinationExceptionWhenDestinationIsWrongType()
{
$this->expectException(InvalidDestinationException::class);
$this->expectExceptionMessage('The destination must be an instance of');
$producer = new StompProducer($this->createStompClientMock());
$producer->send($this->createMock(PsrQueue::class), new StompMessage());
}
public function testShouldThrowInvalidMessageExceptionWhenMessageIsWrongType()
{
$this->expectException(InvalidMessageException::class);
$this->expectExceptionMessage('The message must be an instance of');
$producer = new StompProducer($this->createStompClientMock());
$producer->send(new StompDestination(), $this->createMock(PsrMessage::class));
}
public function testShouldSendMessage()
{
$client = $this->createStompClientMock();
$client
->expects($this->once())
->method('send')
->with('/queue/name', $this->isInstanceOf(Message::class))
;
$producer = new StompProducer($client);
$destination = new StompDestination();
$destination->setType(StompDestination::TYPE_QUEUE);
$destination->setStompName('name');
$producer->send($destination, new StompMessage('body'));
}
public function testShouldEncodeMessageHeadersAndProperties()
{
$stompMessage = null;
$client = $this->createStompClientMock();
$client
->expects($this->once())
->method('send')
->willReturnCallback(function ($destination, Message $message) use (&$stompMessage) {
$stompMessage = $message;
})
;
$producer = new StompProducer($client);
$message = new StompMessage('', ['key' => 'value'], ['hkey' => false]);
$destination = new StompDestination();
$destination->setType(StompDestination::TYPE_QUEUE);
$destination->setStompName('name');
$producer->send($destination, $message);
$expectedHeaders = [
'hkey' => 'false',
'durable' => 'false',
'auto-delete' => 'true',
'exclusive' => 'false',
'_type_hkey' => 'b',
'_type_durable' => 'b',
'_type_auto-delete' => 'b',
'_type_exclusive' => 'b',
'_property_key' => 'value',
'_property__type_key' => 's',
];
$this->assertEquals($expectedHeaders, $stompMessage->getHeaders());
}
/**
* @return \PHPUnit_Framework_MockObject_MockObject|Client
*/
private function createStompClientMock()
{
return $this->createMock(Client::class);
}
}