Skip to content

Commit c202212

Browse files
committed
fix stomp tests.
1 parent 6c352c1 commit c202212

7 files changed

+57
-41
lines changed

pkg/stomp/StompConsumer.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public function receive(int $timeout = 0): ?PsrMessage
105105
return $this->convertMessage($message);
106106
}
107107
}
108+
109+
return null;
108110
}
109111

110112
public function receiveNoWait(): ?PsrMessage
@@ -114,6 +116,8 @@ public function receiveNoWait(): ?PsrMessage
114116
if ($message = $this->stomp->readMessageFrame($this->subscriptionId, 0)) {
115117
return $this->convertMessage($message);
116118
}
119+
120+
return null;
117121
}
118122

119123
/**
@@ -195,7 +199,7 @@ private function convertMessage(Frame $frame): StompMessage
195199
$headers['content-length']
196200
);
197201

198-
$message = new StompMessage($frame->getBody(), $properties, $headers);
202+
$message = new StompMessage((string) $frame->getBody(), $properties, $headers);
199203
$message->setRedelivered($redelivered);
200204
$message->setFrame($frame);
201205

pkg/stomp/StompDestination.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function setStompName(string $name): void
5959

6060
public function getQueueName(): string
6161
{
62-
if (empty($this->getType()) || empty($this->getStompName())) {
63-
throw new \LogicException('Destination type or name is not set');
62+
if (empty($this->getStompName())) {
63+
throw new \LogicException('Destination name is not set');
6464
}
6565

6666
$name = '/'.$this->getType().'/'.$this->getStompName();

pkg/stomp/Tests/Client/RabbitMqStompDriverTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,11 @@ public function testShouldSendMessageToProcessor()
406406
public function testShouldSendMessageToDelayExchangeIfDelaySet()
407407
{
408408
$queue = new StompDestination();
409+
$queue->setStompName('queueName');
410+
409411
$delayTopic = new StompDestination();
412+
$delayTopic->setStompName('delayTopic');
413+
410414
$transportMessage = new StompMessage();
411415

412416
$producer = $this->createPsrProducerMock();

pkg/stomp/Tests/StompConsumerTest.php

+32-23
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,26 @@ public function testShouldImplementMessageConsumerInterface()
2424

2525
public function testCouldBeConstructedWithRequiredAttributes()
2626
{
27-
new StompConsumer($this->createStompClientMock(), new StompDestination());
27+
new StompConsumer($this->createStompClientMock(), $this->createDummyDestination());
2828
}
2929

3030
public function testCouldGetQueue()
3131
{
32-
$consumer = new StompConsumer($this->createStompClientMock(), $dest = new StompDestination());
32+
$consumer = new StompConsumer($this->createStompClientMock(), $dest = $this->createDummyDestination());
3333

3434
$this->assertSame($dest, $consumer->getQueue());
3535
}
3636

3737
public function testShouldReturnDefaultAckMode()
3838
{
39-
$consumer = new StompConsumer($this->createStompClientMock(), new StompDestination());
39+
$consumer = new StompConsumer($this->createStompClientMock(), $this->createDummyDestination());
4040

4141
$this->assertSame(StompConsumer::ACK_CLIENT_INDIVIDUAL, $consumer->getAckMode());
4242
}
4343

4444
public function testCouldSetGetAckMethod()
4545
{
46-
$consumer = new StompConsumer($this->createStompClientMock(), new StompDestination());
46+
$consumer = new StompConsumer($this->createStompClientMock(), $this->createDummyDestination());
4747
$consumer->setAckMode(StompConsumer::ACK_CLIENT);
4848

4949
$this->assertSame(StompConsumer::ACK_CLIENT, $consumer->getAckMode());
@@ -54,20 +54,20 @@ public function testShouldThrowLogicExceptionIfAckModeIsInvalid()
5454
$this->expectException(\LogicException::class);
5555
$this->expectExceptionMessage('Ack mode is not valid: "invalid-ack-mode"');
5656

57-
$consumer = new StompConsumer($this->createStompClientMock(), new StompDestination());
57+
$consumer = new StompConsumer($this->createStompClientMock(), $this->createDummyDestination());
5858
$consumer->setAckMode('invalid-ack-mode');
5959
}
6060

6161
public function testShouldReturnDefaultPrefetchCount()
6262
{
63-
$consumer = new StompConsumer($this->createStompClientMock(), new StompDestination());
63+
$consumer = new StompConsumer($this->createStompClientMock(), $this->createDummyDestination());
6464

6565
$this->assertSame(1, $consumer->getPrefetchCount());
6666
}
6767

6868
public function testCouldSetGetPrefetchCount()
6969
{
70-
$consumer = new StompConsumer($this->createStompClientMock(), new StompDestination());
70+
$consumer = new StompConsumer($this->createStompClientMock(), $this->createDummyDestination());
7171
$consumer->setPrefetchCount(123);
7272

7373
$this->assertSame(123, $consumer->getPrefetchCount());
@@ -78,7 +78,7 @@ public function testAcknowledgeShouldThrowInvalidMessageExceptionIfMessageIsWron
7878
$this->expectException(InvalidMessageException::class);
7979
$this->expectExceptionMessage('The message must be an instance of');
8080

81-
$consumer = new StompConsumer($this->createStompClientMock(), new StompDestination());
81+
$consumer = new StompConsumer($this->createStompClientMock(), $this->createDummyDestination());
8282
$consumer->acknowledge($this->createMock(PsrMessage::class));
8383
}
8484

@@ -106,7 +106,7 @@ public function testShouldAcknowledgeMessage()
106106
$message = new StompMessage();
107107
$message->setFrame(new Frame());
108108

109-
$consumer = new StompConsumer($client, new StompDestination());
109+
$consumer = new StompConsumer($client, $this->createDummyDestination());
110110
$consumer->acknowledge($message);
111111
}
112112

@@ -115,7 +115,7 @@ public function testRejectShouldThrowInvalidMessageExceptionIfMessageIsWrongType
115115
$this->expectException(InvalidMessageException::class);
116116
$this->expectExceptionMessage('The message must be an instance of');
117117

118-
$consumer = new StompConsumer($this->createStompClientMock(), new StompDestination());
118+
$consumer = new StompConsumer($this->createStompClientMock(), $this->createDummyDestination());
119119
$consumer->reject($this->createMock(PsrMessage::class));
120120
}
121121

@@ -143,7 +143,7 @@ public function testShouldRejectMessage()
143143
$message = new StompMessage();
144144
$message->setFrame(new Frame());
145145

146-
$consumer = new StompConsumer($client, new StompDestination());
146+
$consumer = new StompConsumer($client, $this->createDummyDestination());
147147
$consumer->reject($message);
148148

149149
$this->assertSame(['requeue' => 'false'], $frame->getHeaders());
@@ -173,7 +173,7 @@ public function testShouldRejectAndRequeueMessage()
173173
$message = new StompMessage();
174174
$message->setFrame(new Frame());
175175

176-
$consumer = new StompConsumer($client, new StompDestination());
176+
$consumer = new StompConsumer($client, $this->createDummyDestination());
177177
$consumer->reject($message, true);
178178

179179
$this->assertSame(['requeue' => 'true'], $frame->getHeaders());
@@ -210,7 +210,7 @@ public function testShouldReceiveMessageNoWait()
210210
$message = new StompMessage();
211211
$message->setFrame(new Frame());
212212

213-
$destination = new StompDestination();
213+
$destination = $this->createDummyDestination();
214214
$destination->setType(StompDestination::TYPE_QUEUE);
215215
$destination->setStompName('name');
216216

@@ -247,7 +247,7 @@ public function testReceiveMessageNoWaitShouldSubscribeOnlyOnce()
247247
$message = new StompMessage();
248248
$message->setFrame(new Frame());
249249

250-
$destination = new StompDestination();
250+
$destination = $this->createDummyDestination();
251251
$destination->setType(StompDestination::TYPE_QUEUE);
252252
$destination->setStompName('name');
253253

@@ -280,7 +280,7 @@ public function testShouldAddExtraHeadersOnSubscribe()
280280
->method('readMessageFrame')
281281
;
282282

283-
$destination = new StompDestination();
283+
$destination = $this->createDummyDestination();
284284
$destination->setStompName('name');
285285
$destination->setType(StompDestination::TYPE_QUEUE);
286286
$destination->setDurable(true);
@@ -340,7 +340,7 @@ public function testShouldConvertStompMessageFrameToMessage()
340340
->willReturn($stompMessageFrame)
341341
;
342342

343-
$destination = new StompDestination();
343+
$destination = $this->createDummyDestination();
344344
$destination->setStompName('name');
345345
$destination->setType(StompDestination::TYPE_QUEUE);
346346

@@ -381,7 +381,7 @@ public function testShouldThrowLogicExceptionIfFrameIsNotMessageFrame()
381381
->willReturn($stompMessageFrame)
382382
;
383383

384-
$destination = new StompDestination();
384+
$destination = $this->createDummyDestination();
385385
$destination->setStompName('name');
386386
$destination->setType(StompDestination::TYPE_QUEUE);
387387

@@ -418,7 +418,7 @@ public function testShouldReceiveWithUnlimitedTimeout()
418418
->willReturn(new Frame('MESSAGE'))
419419
;
420420

421-
$destination = new StompDestination();
421+
$destination = $this->createDummyDestination();
422422
$destination->setStompName('name');
423423
$destination->setType(StompDestination::TYPE_QUEUE);
424424

@@ -454,7 +454,7 @@ public function testShouldReceiveWithTimeout()
454454
->willReturn(new Frame('MESSAGE'))
455455
;
456456

457-
$destination = new StompDestination();
457+
$destination = $this->createDummyDestination();
458458
$destination->setStompName('name');
459459
$destination->setType(StompDestination::TYPE_QUEUE);
460460

@@ -480,7 +480,7 @@ public function testShouldReceiveWithoutSubscribeIfTempQueue()
480480
$message = new StompMessage();
481481
$message->setFrame(new Frame());
482482

483-
$destination = new StompDestination();
483+
$destination = $this->createDummyDestination();
484484
$destination->setType(StompDestination::TYPE_TEMP_QUEUE);
485485
$destination->setStompName('name');
486486

@@ -503,7 +503,7 @@ public function testShouldReceiveNoWaitWithoutSubscribeIfTempQueue()
503503
$message = new StompMessage();
504504
$message->setFrame(new Frame());
505505

506-
$destination = new StompDestination();
506+
$destination = $this->createDummyDestination();
507507
$destination->setType(StompDestination::TYPE_TEMP_QUEUE);
508508
$destination->setStompName('name');
509509

@@ -513,7 +513,7 @@ public function testShouldReceiveNoWaitWithoutSubscribeIfTempQueue()
513513

514514
public function testShouldGenerateUniqueSubscriptionIdPerConsumer()
515515
{
516-
$destination = new StompDestination();
516+
$destination = $this->createDummyDestination();
517517
$destination->setType(StompDestination::TYPE_QUEUE);
518518
$destination->setStompName('name');
519519

@@ -530,7 +530,7 @@ public function testShouldGenerateUniqueSubscriptionIdPerConsumer()
530530

531531
public function testShouldUseTempQueueNameAsSubscriptionId()
532532
{
533-
$destination = new StompDestination();
533+
$destination = $this->createDummyDestination();
534534
$destination->setType(StompDestination::TYPE_TEMP_QUEUE);
535535
$destination->setStompName('foo');
536536

@@ -554,4 +554,13 @@ private function createStompClientMock()
554554
{
555555
return $this->createMock(BufferedStompClient::class);
556556
}
557+
558+
private function createDummyDestination(): StompDestination
559+
{
560+
$destination = new StompDestination();
561+
$destination->setStompName('aName');
562+
$destination->setType(StompDestination::TYPE_QUEUE);
563+
564+
return $destination;
565+
}
557566
}

pkg/stomp/Tests/StompContextTest.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function testShouldCreateMessageConsumerInstance()
117117
{
118118
$context = new StompContext($this->createStompClientMock());
119119

120-
$this->assertInstanceOf(StompConsumer::class, $context->createConsumer(new StompDestination()));
120+
$this->assertInstanceOf(StompConsumer::class, $context->createConsumer($this->createDummyDestination()));
121121
}
122122

123123
public function testShouldCreateMessageProducerInstance()
@@ -138,7 +138,7 @@ public function testShouldCloseConnections()
138138
$context = new StompContext($client);
139139

140140
$context->createProducer();
141-
$context->createConsumer(new StompDestination());
141+
$context->createConsumer($this->createDummyDestination());
142142

143143
$context->close();
144144
}
@@ -220,4 +220,13 @@ private function createStompClientMock()
220220
{
221221
return $this->createMock(BufferedStompClient::class);
222222
}
223+
224+
private function createDummyDestination(): StompDestination
225+
{
226+
$destination = new StompDestination();
227+
$destination->setStompName('aName');
228+
$destination->setType(StompDestination::TYPE_QUEUE);
229+
230+
return $destination;
231+
}
223232
}

pkg/stomp/Tests/StompDestinationTest.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,11 @@ public function testShouldReturnDestinationStringWithoutRoutingKey()
4545
public function testShouldThrowLogicExceptionIfNameIsNotSet()
4646
{
4747
$this->expectException(\LogicException::class);
48-
$this->expectExceptionMessage('Destination type or name is not set');
48+
$this->expectExceptionMessage('Destination name is not set');
4949

5050
$destination = new StompDestination();
5151
$destination->setType(StompDestination::TYPE_QUEUE);
52-
53-
$destination->getQueueName();
54-
}
55-
56-
public function testShouldThrowLogicExceptionIfTypeIsNotSet()
57-
{
58-
$this->expectException(\LogicException::class);
59-
$this->expectExceptionMessage('Destination type or name is not set');
60-
61-
$destination = new StompDestination();
62-
$destination->setStompName('name');
52+
$destination->setStompName('');
6353

6454
$destination->getQueueName();
6555
}

pkg/stomp/composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"require": {
99
"php": "^7.1.3",
1010
"stomp-php/stomp-php": "^4",
11-
"queue-interop/queue-interop": "^0.6.2",
11+
"queue-interop/queue-interop": "0.7.x-dev",
1212
"php-http/guzzle6-adapter": "^1.1",
1313
"php-http/client-common": "^1.7@dev",
1414
"richardfullmer/rabbitmq-management-api": "^2.0"

0 commit comments

Comments
 (0)