Repository navigation
Expand file tree
/
Copy pathRabbitMqDriverTest.php
More file actions
141 lines (123 loc) · 3.98 KB
/
Copy pathRabbitMqDriverTest.php
File metadata and controls
141 lines (123 loc) · 3.98 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
<?php
namespace Enqueue\Tests\Client\Driver;
use Enqueue\Client\Config;
use Enqueue\Client\Driver\AmqpDriver;
use Enqueue\Client\Driver\GenericDriver;
use Enqueue\Client\Driver\RabbitMqDriver;
use Enqueue\Client\DriverInterface;
use Enqueue\Client\MessagePriority;
use Enqueue\Client\RouteCollection;
use Enqueue\Test\ClassExtensionTrait;
use Interop\Amqp\AmqpContext;
use Interop\Amqp\AmqpProducer;
use Interop\Amqp\Impl\AmqpMessage;
use Interop\Amqp\Impl\AmqpQueue;
use Interop\Amqp\Impl\AmqpTopic;
use Interop\Queue\Context;
use Interop\Queue\Message as InteropMessage;
use Interop\Queue\Producer as InteropProducer;
use Interop\Queue\Queue as InteropQueue;
use PHPUnit\Framework\TestCase;
class RabbitMqDriverTest extends TestCase
{
use ClassExtensionTrait;
use GenericDriverTestsTrait;
public function testShouldImplementsDriverInterface()
{
$this->assertClassImplements(DriverInterface::class, RabbitMqDriver::class);
}
public function testShouldBeSubClassOfGenericDriver()
{
$this->assertClassExtends(GenericDriver::class, RabbitMqDriver::class);
}
public function testShouldBeSubClassOfAmqpDriver()
{
$this->assertClassExtends(AmqpDriver::class, RabbitMqDriver::class);
}
public function testShouldCreateQueueWithMaxPriorityArgument()
{
$context = $this->createContextMock();
$context
->expects($this->once())
->method('createQueue')
->willReturn($this->createQueue('aName'))
;
$driver = $this->createDriver(
$context,
$this->createDummyConfig(),
new RouteCollection([])
);
/** @var AmqpQueue $queue */
$queue = $driver->createQueue('aName');
$this->assertSame(['x-max-priority' => 4], $queue->getArguments());
}
protected function createDriver(...$args): DriverInterface
{
return new RabbitMqDriver(...$args);
}
/**
* @return AmqpContext
*/
protected function createContextMock(): Context
{
return $this->createMock(AmqpContext::class);
}
/**
* @return AmqpProducer
*/
protected function createProducerMock(): InteropProducer
{
return $this->createMock(AmqpProducer::class);
}
/**
* @return AmqpQueue
*/
protected function createQueue(string $name): InteropQueue
{
return new AmqpQueue($name);
}
/**
* @return AmqpTopic
*/
protected function createTopic(string $name): AmqpTopic
{
return new AmqpTopic($name);
}
/**
* @return AmqpMessage
*/
protected function createMessage(): InteropMessage
{
return new AmqpMessage();
}
protected function getRouterTransportName(): string
{
return 'aprefix.router';
}
protected function assertTransportMessage(InteropMessage $transportMessage): void
{
$this->assertSame('body', $transportMessage->getBody());
$this->assertArraySubset([
'hkey' => 'hval',
'delivery_mode' => AmqpMessage::DELIVERY_MODE_PERSISTENT,
'content_type' => 'ContentType',
'expiration' => '123000',
'priority' => 3,
'message_id' => 'theMessageId',
'timestamp' => 1000,
'reply_to' => 'theReplyTo',
'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());
}
}