Skip to content

Commit 6c30be4

Browse files
committed
amqp lib interop
1 parent 5e8920a commit 6c30be4

1 file changed

Lines changed: 112 additions & 3 deletions

File tree

‎pkg/amqp-lib/Tests/AmqpContextTest.php‎

Lines changed: 112 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,36 @@ public function testShouldDeclareTopic()
5151
$session->declareTopic($topic);
5252
}
5353

54+
public function testShouldDeleteTopic()
55+
{
56+
$channel = $this->createChannelMock();
57+
$channel
58+
->expects($this->once())
59+
->method('exchange_delete')
60+
->with(
61+
$this->identicalTo('name'),
62+
$this->isTrue(),
63+
$this->isTrue()
64+
)
65+
;
66+
67+
$connection = $this->createConnectionMock();
68+
$connection
69+
->expects($this->once())
70+
->method('channel')
71+
->willReturn($channel)
72+
;
73+
74+
$topic = new AmqpTopic('name');
75+
$topic->setType('type');
76+
$topic->setArguments(['key' => 'value']);
77+
$topic->addFlag(AmqpTopic::FLAG_IFUNUSED);
78+
$topic->addFlag(AmqpTopic::FLAG_NOWAIT);
79+
80+
$session = new AmqpContext($connection, '');
81+
$session->deleteTopic($topic);
82+
}
83+
5484
public function testShouldDeclareQueue()
5585
{
5686
$channel = $this->createChannelMock();
@@ -89,7 +119,38 @@ public function testShouldDeclareQueue()
89119
$session->declareQueue($queue);
90120
}
91121

92-
public function testDeclareBindShouldBindTopicToTopic()
122+
public function testShouldDeleteQueue()
123+
{
124+
$channel = $this->createChannelMock();
125+
$channel
126+
->expects($this->once())
127+
->method('queue_delete')
128+
->with(
129+
$this->identicalTo('name'),
130+
$this->isTrue(),
131+
$this->isTrue(),
132+
$this->isTrue()
133+
)
134+
;
135+
136+
$connection = $this->createConnectionMock();
137+
$connection
138+
->expects($this->once())
139+
->method('channel')
140+
->willReturn($channel)
141+
;
142+
143+
$queue = new AmqpQueue('name');
144+
$queue->setArguments(['key' => 'value']);
145+
$queue->addFlag(AmqpQueue::FLAG_IFUNUSED);
146+
$queue->addFlag(AmqpQueue::FLAG_IFEMPTY);
147+
$queue->addFlag(AmqpQueue::FLAG_NOWAIT);
148+
149+
$session = new AmqpContext($connection, '');
150+
$session->deleteQueue($queue);
151+
}
152+
153+
public function testBindShouldBindTopicToTopic()
93154
{
94155
$source = new AmqpTopic('source');
95156
$target = new AmqpTopic('target');
@@ -112,7 +173,7 @@ public function testDeclareBindShouldBindTopicToTopic()
112173
$context->bind(new AmqpBind($target, $source, 'routing-key', 12345));
113174
}
114175

115-
public function testDeclareBindShouldBindTopicToQueue()
176+
public function testBindShouldBindTopicToQueue()
116177
{
117178
$source = new AmqpTopic('source');
118179
$target = new AmqpQueue('target');
@@ -136,6 +197,53 @@ public function testDeclareBindShouldBindTopicToQueue()
136197
$context->bind(new AmqpBind($source, $target, 'routing-key', 12345));
137198
}
138199

200+
public function testShouldUnBindTopicFromTopic()
201+
{
202+
$source = new AmqpTopic('source');
203+
$target = new AmqpTopic('target');
204+
205+
$channel = $this->createChannelMock();
206+
$channel
207+
->expects($this->once())
208+
->method('exchange_unbind')
209+
->with($this->identicalTo('target'), $this->identicalTo('source'), $this->identicalTo('routing-key'), $this->isTrue())
210+
;
211+
212+
$connection = $this->createConnectionMock();
213+
$connection
214+
->expects($this->once())
215+
->method('channel')
216+
->willReturn($channel)
217+
;
218+
219+
$context = new AmqpContext($connection, '');
220+
$context->unbind(new AmqpBind($target, $source, 'routing-key', 12345));
221+
}
222+
223+
public function testShouldUnBindTopicFromQueue()
224+
{
225+
$source = new AmqpTopic('source');
226+
$target = new AmqpQueue('target');
227+
228+
$channel = $this->createChannelMock();
229+
$channel
230+
->expects($this->exactly(2))
231+
->method('queue_unbind')
232+
->with($this->identicalTo('target'), $this->identicalTo('source'), $this->identicalTo('routing-key'), ['key' => 'value'])
233+
;
234+
235+
$connection = $this->createConnectionMock();
236+
$connection
237+
->expects($this->once())
238+
->method('channel')
239+
->willReturn($channel)
240+
;
241+
242+
$context = new AmqpContext($connection, '');
243+
$context->unbind(new AmqpBind($target, $source, 'routing-key', 12345, ['key' => 'value']));
244+
$context->unbind(new AmqpBind($source, $target, 'routing-key', 12345, ['key' => 'value']));
245+
}
246+
139247
public function testShouldCloseChannelConnection()
140248
{
141249
$channel = $this->createChannelMock();
@@ -160,12 +268,13 @@ public function testShouldCloseChannelConnection()
160268
public function testShouldPurgeQueue()
161269
{
162270
$queue = new AmqpQueue('queue');
271+
$queue->addFlag(AmqpQueue::FLAG_NOWAIT);
163272

164273
$channel = $this->createChannelMock();
165274
$channel
166275
->expects($this->once())
167276
->method('queue_purge')
168-
->with('queue')
277+
->with($this->identicalTo('queue'), $this->isTrue())
169278
;
170279

171280
$connection = $this->createConnectionMock();

0 commit comments

Comments
 (0)