Skip to content

Commit f08e2af

Browse files
committed
add driver send result
1 parent 2f6e902 commit f08e2af

6 files changed

Lines changed: 137 additions & 5 deletions

File tree

‎pkg/enqueue/Tests/Client/ChainExtensionTest.php‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Enqueue\Client\PreSend;
1212
use Enqueue\Client\ProducerInterface;
1313
use Enqueue\Test\ClassExtensionTrait;
14+
use Interop\Queue\Destination;
15+
use Interop\Queue\Message as TransportMessage;
1416
use PHPUnit\Framework\TestCase;
1517

1618
class ChainExtensionTest extends TestCase
@@ -132,7 +134,9 @@ public function testShouldProxyOnPostSentToAllInternalExtensions()
132134
$postSend = new PostSend(
133135
new Message(),
134136
$this->createMock(ProducerInterface::class),
135-
$this->createMock(DriverInterface::class)
137+
$this->createMock(DriverInterface::class),
138+
$this->createMock(Destination::class),
139+
$this->createMock(TransportMessage::class)
136140
);
137141

138142
$fooExtension = $this->createExtension();

‎pkg/enqueue/Tests/Client/ConsumptionExtension/DelayRedeliveredMessageExtensionTest.php‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
use Enqueue\Client\ConsumptionExtension\DelayRedeliveredMessageExtension;
66
use Enqueue\Client\DriverInterface;
7+
use Enqueue\Client\DriverSendResult;
78
use Enqueue\Client\Message;
89
use Enqueue\Consumption\Context\MessageReceived;
910
use Enqueue\Consumption\Result;
1011
use Enqueue\Null\NullMessage;
1112
use Enqueue\Null\NullQueue;
1213
use Interop\Queue\Consumer;
1314
use Interop\Queue\Context as InteropContext;
15+
use Interop\Queue\Destination;
16+
use Interop\Queue\Message as TransportMessage;
1417
use Interop\Queue\Processor;
1518
use PHPUnit\Framework\TestCase;
1619
use Psr\Log\LoggerInterface;
@@ -41,6 +44,7 @@ public function testShouldSendDelayedMessageAndRejectOriginalMessage()
4144
->expects(self::once())
4245
->method('sendToProcessor')
4346
->with(self::isInstanceOf(Message::class))
47+
->willReturn($this->createDriverSendResult())
4448
;
4549
$driver
4650
->expects(self::once())
@@ -187,4 +191,12 @@ private function createLoggerMock(): LoggerInterface
187191
{
188192
return $this->createMock(LoggerInterface::class);
189193
}
194+
195+
private function createDriverSendResult(): DriverSendResult
196+
{
197+
return new DriverSendResult(
198+
$this->createMock(Destination::class),
199+
$this->createMock(TransportMessage::class)
200+
);
201+
}
190202
}

‎pkg/enqueue/Tests/Client/PostSendTest.php‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Enqueue\Client\PostSend;
99
use Enqueue\Client\ProducerInterface;
1010
use Enqueue\Test\ClassExtensionTrait;
11+
use Interop\Queue\Destination;
12+
use Interop\Queue\Message as TransportMessage;
1113
use PHPUnit\Framework\TestCase;
1214

1315
class PostSendTest extends TestCase
@@ -24,7 +26,9 @@ public function testCouldBeConstructedWithExpectedArguments()
2426
new PostSend(
2527
new Message(),
2628
$this->createProducerMock(),
27-
$this->createDriverMock()
29+
$this->createDriverMock(),
30+
$this->createDestinationMock(),
31+
$this->createTransportMessageMock()
2832
);
2933
}
3034

@@ -33,16 +37,22 @@ public function testShouldAllowGetArgumentSetInConstructor()
3337
$expectedMessage = new Message();
3438
$expectedProducer = $this->createProducerMock();
3539
$expectedDriver = $this->createDriverMock();
40+
$expectedDestination = $this->createDestinationMock();
41+
$expectedTransportMessage = $this->createTransportMessageMock();
3642

3743
$context = new PostSend(
3844
$expectedMessage,
3945
$expectedProducer,
40-
$expectedDriver
46+
$expectedDriver,
47+
$expectedDestination,
48+
$expectedTransportMessage
4149
);
4250

4351
$this->assertSame($expectedMessage, $context->getMessage());
4452
$this->assertSame($expectedProducer, $context->getProducer());
4553
$this->assertSame($expectedDriver, $context->getDriver());
54+
$this->assertSame($expectedDestination, $context->getTransportDestination());
55+
$this->assertSame($expectedTransportMessage, $context->getTransportMessage());
4656
}
4757

4858
public function testShouldAllowGetCommand()
@@ -53,7 +63,9 @@ public function testShouldAllowGetCommand()
5363
$context = new PostSend(
5464
$message,
5565
$this->createProducerMock(),
56-
$this->createDriverMock()
66+
$this->createDriverMock(),
67+
$this->createDestinationMock(),
68+
$this->createTransportMessageMock()
5769
);
5870

5971
$this->assertFalse($context->isEvent());
@@ -68,7 +80,9 @@ public function testShouldAllowGetTopic()
6880
$context = new PostSend(
6981
$message,
7082
$this->createProducerMock(),
71-
$this->createDriverMock()
83+
$this->createDriverMock(),
84+
$this->createDestinationMock(),
85+
$this->createTransportMessageMock()
7286
);
7387

7488
$this->assertTrue($context->isEvent());
@@ -90,4 +104,20 @@ private function createProducerMock(): ProducerInterface
90104
{
91105
return $this->createMock(ProducerInterface::class);
92106
}
107+
108+
/**
109+
* @return \PHPUnit_Framework_MockObject_MockObject|Destination
110+
*/
111+
private function createDestinationMock(): Destination
112+
{
113+
return $this->createMock(Destination::class);
114+
}
115+
116+
/**
117+
* @return \PHPUnit_Framework_MockObject_MockObject|TransportMessage
118+
*/
119+
private function createTransportMessageMock(): TransportMessage
120+
{
121+
return $this->createMock(TransportMessage::class);
122+
}
93123
}

‎pkg/enqueue/Tests/Client/ProducerSendCommandTest.php‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Enqueue\Client\Config;
66
use Enqueue\Client\DriverInterface;
77
use Enqueue\Client\DriverPreSend;
8+
use Enqueue\Client\DriverSendResult;
89
use Enqueue\Client\ExtensionInterface;
910
use Enqueue\Client\Message;
1011
use Enqueue\Client\MessagePriority;
@@ -15,6 +16,8 @@
1516
use Enqueue\Rpc\RpcFactory;
1617
use Enqueue\Test\ClassExtensionTrait;
1718
use Enqueue\Tests\Mocks\CustomPrepareBodyClientExtension;
19+
use Interop\Queue\Destination;
20+
use Interop\Queue\Message as TransportMessage;
1821
use PHPUnit\Framework\TestCase;
1922

2023
class ProducerSendCommandTest extends TestCase
@@ -30,6 +33,7 @@ public function testShouldSendCommandToProcessor()
3033
->expects($this->once())
3134
->method('sendToProcessor')
3235
->with(self::identicalTo($message))
36+
->willReturn($this->createDriverSendResult())
3337
;
3438
$driver
3539
->expects($this->never())
@@ -55,6 +59,7 @@ public function testShouldSendCommandWithReply()
5559
->expects($this->once())
5660
->method('sendToProcessor')
5761
->with(self::identicalTo($message))
62+
->willReturn($this->createDriverSendResult())
5863
;
5964
$driver
6065
->expects($this->never())
@@ -100,6 +105,7 @@ public function testShouldSendCommandWithReplyAndCustomReplyQueueAndCorrelationI
100105
->expects($this->once())
101106
->method('sendToProcessor')
102107
->with(self::identicalTo($message))
108+
->willReturn($this->createDriverSendResult())
103109
;
104110
$driver
105111
->expects($this->never())
@@ -140,6 +146,11 @@ public function testShouldOverwriteExpectedMessageProperties()
140146
$message->setScope('scopeShouldBeOverwritten');
141147

142148
$driver = $this->createDriverStub();
149+
$driver
150+
->expects($this->once())
151+
->method('sendToProcessor')
152+
->willReturn($this->createDriverSendResult())
153+
;
143154

144155
$producer = new Producer($driver, $this->createRpcFactoryMock());
145156
$producer->sendCommand('expectedCommand', $message);
@@ -161,6 +172,7 @@ public function testShouldSendCommandWithoutPriorityByDefault()
161172
->expects($this->once())
162173
->method('sendToProcessor')
163174
->with(self::identicalTo($message))
175+
->willReturn($this->createDriverSendResult())
164176
;
165177

166178
$producer = new Producer($driver, $this->createRpcFactoryMock());
@@ -179,6 +191,7 @@ public function testShouldSendCommandWithCustomPriority()
179191
->expects($this->once())
180192
->method('sendToProcessor')
181193
->with(self::identicalTo($message))
194+
->willReturn($this->createDriverSendResult())
182195
;
183196

184197
$producer = new Producer($driver, $this->createRpcFactoryMock());
@@ -196,6 +209,7 @@ public function testShouldSendCommandWithGeneratedMessageId()
196209
->expects($this->once())
197210
->method('sendToProcessor')
198211
->with(self::identicalTo($message))
212+
->willReturn($this->createDriverSendResult())
199213
;
200214

201215
$producer = new Producer($driver, $this->createRpcFactoryMock());
@@ -214,6 +228,7 @@ public function testShouldSendCommandWithCustomMessageId()
214228
->expects($this->once())
215229
->method('sendToProcessor')
216230
->with(self::identicalTo($message))
231+
->willReturn($this->createDriverSendResult())
217232
;
218233

219234
$producer = new Producer($driver, $this->createRpcFactoryMock());
@@ -231,6 +246,7 @@ public function testShouldSendCommandWithGeneratedTimestamp()
231246
->expects($this->once())
232247
->method('sendToProcessor')
233248
->with(self::identicalTo($message))
249+
->willReturn($this->createDriverSendResult())
234250
;
235251

236252
$producer = new Producer($driver, $this->createRpcFactoryMock());
@@ -249,6 +265,7 @@ public function testShouldSendCommandWithCustomTimestamp()
249265
->expects($this->once())
250266
->method('sendToProcessor')
251267
->with(self::identicalTo($message))
268+
->willReturn($this->createDriverSendResult())
252269
;
253270

254271
$producer = new Producer($driver, $this->createRpcFactoryMock());
@@ -265,6 +282,8 @@ public function testShouldSerializeMessageToJsonByDefault()
265282
->method('sendToProcessor')
266283
->willReturnCallback(function (Message $message) {
267284
$this->assertSame('{"foo":"fooVal"}', $message->getBody());
285+
286+
return $this->createDriverSendResult();
268287
})
269288
;
270289

@@ -280,6 +299,8 @@ public function testShouldSerializeMessageByCustomExtension()
280299
->method('sendToProcessor')
281300
->willReturnCallback(function (Message $message) {
282301
$this->assertSame('theCommandBodySerializedByCustomExtension', $message->getBody());
302+
303+
return $this->createDriverSendResult();
283304
})
284305
;
285306

@@ -301,6 +322,8 @@ public function testShouldSendCommandToApplicationRouter()
301322
self::assertSame('aBody', $message->getBody());
302323
self::assertNull($message->getProperty(Config::PROCESSOR));
303324
self::assertSame('command', $message->getProperty(Config::COMMAND));
325+
326+
return $this->createDriverSendResult();
304327
})
305328
;
306329

@@ -338,6 +361,7 @@ public function testShouldCallPreSendCommandExtensionMethodWhenSendToBus()
338361
$driver
339362
->expects($this->once())
340363
->method('sendToProcessor')
364+
->willReturn($this->createDriverSendResult())
341365
;
342366

343367
$extension = $this->createMock(ExtensionInterface::class);
@@ -375,6 +399,7 @@ public function testShouldCallPreSendCommandExtensionMethodWhenSendToApplication
375399
$driver
376400
->expects($this->once())
377401
->method('sendToProcessor')
402+
->willReturn($this->createDriverSendResult())
378403
;
379404

380405
$extension = $this->createMock(ExtensionInterface::class);
@@ -412,6 +437,7 @@ public function testShouldCallPreDriverSendExtensionMethod()
412437
$driver
413438
->expects($this->once())
414439
->method('sendToProcessor')
440+
->willReturn($this->createDriverSendResult())
415441
;
416442

417443
$extension = $this->createMock(ExtensionInterface::class);
@@ -443,6 +469,7 @@ public function testShouldCallPostSendExtensionMethod()
443469
$driver
444470
->expects($this->once())
445471
->method('sendToProcessor')
472+
->willReturn($this->createDriverSendResult())
446473
;
447474

448475
$extension = $this->createMock(ExtensionInterface::class);
@@ -495,4 +522,12 @@ private function createDriverStub(): DriverInterface
495522

496523
return $driverMock;
497524
}
525+
526+
private function createDriverSendResult(): DriverSendResult
527+
{
528+
return new DriverSendResult(
529+
$this->createMock(Destination::class),
530+
$this->createMock(TransportMessage::class)
531+
);
532+
}
498533
}

0 commit comments

Comments
 (0)