-
Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathRouteRecipientListProcessorTest.php
95 lines (79 loc) · 2.87 KB
/
RouteRecipientListProcessorTest.php
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
<?php
namespace Enqueue\Tests\Router;
use Enqueue\Consumption\Result;
use Enqueue\NoEffect\NullMessage;
use Enqueue\NoEffect\NullQueue;
use Enqueue\Router\Recipient;
use Enqueue\Router\RecipientListRouterInterface;
use Enqueue\Router\RouteRecipientListProcessor;
use Enqueue\Test\ClassExtensionTrait;
use Interop\Queue\Context;
use Interop\Queue\Processor;
use Interop\Queue\Producer as InteropProducer;
use PHPUnit\Framework\TestCase;
class RouteRecipientListProcessorTest extends TestCase
{
use ClassExtensionTrait;
public function testShouldImplementProcessorInterface()
{
$this->assertClassImplements(Processor::class, RouteRecipientListProcessor::class);
}
public function testCouldBeConstructedWithRouterAsFirstArgument()
{
new RouteRecipientListProcessor($this->createRecipientListRouterMock());
}
public function testShouldProduceRecipientsMessagesAndAckOriginalMessage()
{
$fooRecipient = new Recipient(new NullQueue('aName'), new NullMessage());
$barRecipient = new Recipient(new NullQueue('aName'), new NullMessage());
$originalMessage = new NullMessage();
$routerMock = $this->createRecipientListRouterMock();
$routerMock
->expects($this->once())
->method('route')
->with($this->identicalTo($originalMessage))
->willReturn([$fooRecipient, $barRecipient])
;
$producerMock = $this->createProducerMock();
$producerMock
->expects($this->at(0))
->method('send')
->with($this->identicalTo($fooRecipient->getDestination()), $this->identicalTo($fooRecipient->getMessage()))
;
$producerMock
->expects($this->at(1))
->method('send')
->with($this->identicalTo($barRecipient->getDestination()), $this->identicalTo($barRecipient->getMessage()))
;
$sessionMock = $this->createContextMock();
$sessionMock
->expects($this->once())
->method('createProducer')
->willReturn($producerMock)
;
$processor = new RouteRecipientListProcessor($routerMock);
$status = $processor->process($originalMessage, $sessionMock);
$this->assertEquals(Result::ACK, $status);
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject|InteropProducer
*/
protected function createProducerMock()
{
return $this->createMock(InteropProducer::class);
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject|Context
*/
protected function createContextMock()
{
return $this->createMock(Context::class);
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject|RecipientListRouterInterface
*/
protected function createRecipientListRouterMock()
{
return $this->createMock(RecipientListRouterInterface::class);
}
}