Repository navigation
Expand file tree
/
Copy pathStompDriverTest.php
More file actions
190 lines (162 loc) · 5.38 KB
/
Copy pathStompDriverTest.php
File metadata and controls
190 lines (162 loc) · 5.38 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
namespace Enqueue\Tests\Client\Driver;
use Enqueue\Client\Config;
use Enqueue\Client\Driver\GenericDriver;
use Enqueue\Client\Driver\StompDriver;
use Enqueue\Client\DriverInterface;
use Enqueue\Client\Message;
use Enqueue\Client\MessagePriority;
use Enqueue\Client\RouteCollection;
use Enqueue\Stomp\StompContext;
use Enqueue\Stomp\StompDestination;
use Enqueue\Stomp\StompMessage;
use Enqueue\Stomp\StompProducer;
use Enqueue\Test\ClassExtensionTrait;
use Interop\Queue\Context;
use Interop\Queue\Message as InteropMessage;
use Interop\Queue\Producer as InteropProducer;
use Interop\Queue\Queue as InteropQueue;
use Interop\Queue\Topic as InteropTopic;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
class StompDriverTest extends TestCase
{
use ClassExtensionTrait;
use GenericDriverTestsTrait;
public function testShouldImplementsDriverInterface()
{
$this->assertClassImplements(DriverInterface::class, StompDriver::class);
}
public function testShouldBeSubClassOfGenericDriver()
{
$this->assertClassExtends(GenericDriver::class, StompDriver::class);
}
public function testSetupBrokerShouldOnlyLogMessageThatStompDoesNotSupportBrokerSetup()
{
$driver = new StompDriver(
$this->createContextMock(),
$this->createDummyConfig(),
new RouteCollection([])
);
$logger = $this->createLoggerMock();
$logger
->expects($this->once())
->method('debug')
->with('[StompDriver] Stomp protocol does not support broker configuration')
;
$driver->setupBroker($logger);
}
public function testShouldCreateDurableQueue()
{
$context = $this->createContextMock();
$context
->expects($this->once())
->method('createQueue')
->willReturn($this->createQueue('aName'))
;
$driver = $this->createDriver(
$context,
$this->createDummyConfig(),
new RouteCollection([])
);
/** @var StompDestination $queue */
$queue = $driver->createQueue('aName');
$this->assertTrue($queue->isDurable());
$this->assertFalse($queue->isAutoDelete());
$this->assertFalse($queue->isExclusive());
}
public function testShouldSetPersistedTrueOnCreateTransportMessage()
{
$clientMessage = new Message();
$context = $this->createContextMock();
$context
->expects($this->once())
->method('createMessage')
->willReturn($this->createMessage())
;
$driver = $this->createDriver(
$context,
$this->createDummyConfig(),
new RouteCollection([])
);
/** @var StompMessage $transportMessage */
$transportMessage = $driver->createTransportMessage($clientMessage);
$this->assertTrue($transportMessage->isPersistent());
}
protected function createDriver(...$args): DriverInterface
{
return new StompDriver(...$args);
}
/**
* @return StompContext
*/
protected function createContextMock(): Context
{
return $this->createMock(StompContext::class);
}
/**
* @return StompProducer
*/
protected function createProducerMock(): InteropProducer
{
return $this->createMock(StompProducer::class);
}
/**
* @return StompDestination
*/
protected function createQueue(string $name): InteropQueue
{
$destination = new StompDestination();
$destination->setType(StompDestination::TYPE_QUEUE);
$destination->setStompName($name);
return $destination;
}
/**
* @return StompDestination
*/
protected function createTopic(string $name): InteropTopic
{
$destination = new StompDestination();
$destination->setType(StompDestination::TYPE_TOPIC);
$destination->setStompName($name);
return $destination;
}
/**
* @return StompMessage
*/
protected function createMessage(): InteropMessage
{
return new StompMessage();
}
protected function assertTransportMessage(InteropMessage $transportMessage): void
{
$this->assertSame('body', $transportMessage->getBody());
$this->assertEquals([
'hkey' => 'hval',
'message_id' => 'theMessageId',
'timestamp' => 1000,
'reply-to' => 'theReplyTo',
'persistent' => true,
'correlation_id' => 'theCorrelationId',
], $transportMessage->getHeaders());
$this->assertEquals([
'pkey' => 'pval',
Config::CONTENT_TYPE => 'ContentType',
Config::PRIORITY => MessagePriority::HIGH,
Config::EXPIRE => 123,
Config::DELAY => 345,
], $transportMessage->getProperties());
$this->assertSame('theMessageId', $transportMessage->getMessageId());
$this->assertSame(1000, $transportMessage->getTimestamp());
$this->assertSame('theReplyTo', $transportMessage->getReplyTo());
$this->assertSame('theCorrelationId', $transportMessage->getCorrelationId());
}
protected function createLoggerMock(): LoggerInterface
{
return $this->createMock(LoggerInterface::class);
}
protected function getRouterTransportName(): string
{
return '/topic/aprefix.router';
}
}