Skip to content

Commit a653fa5

Browse files
committed
amqp lib interop
1 parent a8a75f9 commit a653fa5

14 files changed

Lines changed: 66 additions & 148 deletions

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace Enqueue\AmqpLib\Tests;
44

55
use Enqueue\AmqpLib\AmqpConsumer;
6-
use Enqueue\AmqpLib\AmqpMessage;
7-
use Enqueue\AmqpLib\AmqpQueue;
86
use Enqueue\AmqpLib\Buffer;
97
use Enqueue\Null\NullMessage;
108
use Enqueue\Test\ClassExtensionTrait;
119
use Enqueue\Test\WriteAttributeTrait;
10+
use Interop\Amqp\Impl\AmqpMessage;
11+
use Interop\Amqp\Impl\AmqpQueue;
1212
use Interop\Queue\InvalidMessageException;
1313
use Interop\Queue\PsrConsumer;
1414
use PhpAmqpLib\Channel\AMQPChannel;
@@ -48,7 +48,7 @@ public function testOnAcknowledgeShouldThrowExceptionIfNotAmqpMessage()
4848
$consumer = new AmqpConsumer($this->createChannelMock(), new AmqpQueue('aName'), new Buffer(), 'basic_get');
4949

5050
$this->expectException(InvalidMessageException::class);
51-
$this->expectExceptionMessage('The message must be an instance of Enqueue\AmqpLib\AmqpMessage but');
51+
$this->expectExceptionMessage('The message must be an instance of Interop\Amqp\AmqpMessage but');
5252

5353
$consumer->acknowledge(new NullMessage());
5454
}
@@ -58,7 +58,7 @@ public function testOnRejectShouldThrowExceptionIfNotAmqpMessage()
5858
$consumer = new AmqpConsumer($this->createChannelMock(), new AmqpQueue('aName'), new Buffer(), 'basic_get');
5959

6060
$this->expectException(InvalidMessageException::class);
61-
$this->expectExceptionMessage('The message must be an instance of Enqueue\AmqpLib\AmqpMessage but');
61+
$this->expectExceptionMessage('The message must be an instance of Interop\Amqp\AmqpMessage but');
6262

6363
$consumer->reject(new NullMessage());
6464
}
@@ -157,21 +157,19 @@ public function testShouldCallExpectedMethodsWhenReceiveWithBasicConsumeMethod()
157157
->method('basic_consume')
158158
->willReturn('consumer-tag')
159159
;
160-
$channel
161-
->expects($this->once())
162-
->method('basic_qos')
163-
->with($this->identicalTo(0), $this->identicalTo(1), $this->isFalse())
164-
;
165160
$channel
166161
->expects($this->once())
167162
->method('wait')
163+
->willReturnCallback(function() {
164+
usleep(2000);
165+
});
168166
;
169167

170168
$consumer = new AmqpConsumer($channel, new AmqpQueue('aName'), new Buffer(), 'basic_consume');
171169

172170
$message = new AmqpMessage();
173171
$message->setDeliveryTag('delivery-tag');
174-
$consumer->receive();
172+
$consumer->receive(1);
175173
}
176174

177175
/**

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

Lines changed: 22 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
namespace Enqueue\AmqpLib\Tests;
44

55
use Enqueue\AmqpLib\AmqpContext;
6-
use Enqueue\AmqpLib\AmqpQueue;
7-
use Enqueue\AmqpLib\AmqpTopic;
86
use Enqueue\Null\NullQueue;
9-
use Enqueue\Null\NullTopic;
10-
use Interop\Queue\Exception;
7+
use Interop\Amqp\Impl\AmqpBind;
8+
use Interop\Amqp\Impl\AmqpQueue;
9+
use Interop\Amqp\Impl\AmqpTopic;
1110
use Interop\Queue\InvalidDestinationException;
1211
use PhpAmqpLib\Channel\AMQPChannel;
1312
use PhpAmqpLib\Connection\AbstractConnection;
@@ -30,7 +29,7 @@ public function testShouldDeclareTopic()
3029
$this->isTrue(),
3130
$this->isTrue(),
3231
$this->identicalTo(['key' => 'value']),
33-
$this->identicalTo(12345)
32+
$this->isNull()
3433
)
3534
;
3635

@@ -44,13 +43,11 @@ public function testShouldDeclareTopic()
4443
$topic = new AmqpTopic('name');
4544
$topic->setType('type');
4645
$topic->setArguments(['key' => 'value']);
47-
$topic->setAutoDelete(true);
48-
$topic->setDurable(true);
49-
$topic->setInternal(true);
50-
$topic->setNoWait(true);
51-
$topic->setPassive(true);
52-
$topic->setRoutingKey('routing-key');
53-
$topic->setTicket(12345);
46+
$topic->addFlag(AmqpTopic::FLAG_DURABLE);
47+
$topic->addFlag(AmqpTopic::FLAG_NOWAIT);
48+
$topic->addFlag(AmqpTopic::FLAG_PASSIVE);
49+
$topic->addFlag(AmqpTopic::FLAG_INTERNAL);
50+
$topic->addFlag(AmqpTopic::FLAG_AUTODELETE);
5451

5552
$session = new AmqpContext($connection, '');
5653
$session->declareTopic($topic);
@@ -70,7 +67,7 @@ public function testShouldDeclareQueue()
7067
$this->isTrue(),
7168
$this->isTrue(),
7269
$this->identicalTo(['key' => 'value']),
73-
$this->identicalTo(12345)
70+
$this->isNull()
7471
)
7572
;
7673

@@ -83,49 +80,17 @@ public function testShouldDeclareQueue()
8380

8481
$queue = new AmqpQueue('name');
8582
$queue->setArguments(['key' => 'value']);
86-
$queue->setAutoDelete(true);
87-
$queue->setDurable(true);
88-
$queue->setNoWait(true);
89-
$queue->setPassive(true);
90-
$queue->setTicket(12345);
91-
$queue->setConsumerTag('consumer-tag');
92-
$queue->setExclusive(true);
93-
$queue->setNoLocal(true);
83+
$queue->addFlag(AmqpQueue::FLAG_AUTODELETE);
84+
$queue->addFlag(AmqpQueue::FLAG_DURABLE);
85+
$queue->addFlag(AmqpQueue::FLAG_NOWAIT);
86+
$queue->addFlag(AmqpQueue::FLAG_PASSIVE);
87+
$queue->addFlag(AmqpQueue::FLAG_EXCLUSIVE);
88+
$queue->addFlag(AmqpQueue::FLAG_NOWAIT);
9489

9590
$session = new AmqpContext($connection, '');
9691
$session->declareQueue($queue);
9792
}
9893

99-
public function testDeclareBindShouldThrowExceptionIfSourceDestinationIsInvalid()
100-
{
101-
$context = new AmqpContext($this->createConnectionMock(), '');
102-
103-
$this->expectException(InvalidDestinationException::class);
104-
$this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpLib\AmqpTopic but got');
105-
106-
$context->bind(new NullTopic(''), new AmqpTopic('name'));
107-
}
108-
109-
public function testDeclareBindShouldThrowExceptionIfTargetDestinationIsInvalid()
110-
{
111-
$context = new AmqpContext($this->createConnectionMock(), '');
112-
113-
$this->expectException(InvalidDestinationException::class);
114-
$this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpLib\AmqpTopic but got');
115-
116-
$context->bind(new AmqpQueue('name'), new NullTopic(''));
117-
}
118-
119-
public function testDeclareBindShouldThrowExceptionWhenSourceAndTargetAreQueues()
120-
{
121-
$context = new AmqpContext($this->createConnectionMock(), '');
122-
123-
$this->expectException(Exception::class);
124-
$this->expectExceptionMessage('Is not possible to bind queue to queue. It is possible to bind topic to queue or topic to topic');
125-
126-
$context->bind(new AmqpQueue('name'), new AmqpQueue('name'));
127-
}
128-
12994
public function testDeclareBindShouldBindTopicToTopic()
13095
{
13196
$source = new AmqpTopic('source');
@@ -135,7 +100,7 @@ public function testDeclareBindShouldBindTopicToTopic()
135100
$channel
136101
->expects($this->once())
137102
->method('exchange_bind')
138-
->with('target', 'source')
103+
->with($this->identicalTo('target'), $this->identicalTo('source'), $this->identicalTo('routing-key'), $this->isTrue())
139104
;
140105

141106
$connection = $this->createConnectionMock();
@@ -146,7 +111,7 @@ public function testDeclareBindShouldBindTopicToTopic()
146111
;
147112

148113
$context = new AmqpContext($connection, '');
149-
$context->bind($source, $target);
114+
$context->bind(new AmqpBind($target, $source, 'routing-key', 12345));
150115
}
151116

152117
public function testDeclareBindShouldBindTopicToQueue()
@@ -158,7 +123,7 @@ public function testDeclareBindShouldBindTopicToQueue()
158123
$channel
159124
->expects($this->exactly(2))
160125
->method('queue_bind')
161-
->with('target', 'source')
126+
->with($this->identicalTo('target'), $this->identicalTo('source'), $this->identicalTo('routing-key'), $this->isTrue())
162127
;
163128

164129
$connection = $this->createConnectionMock();
@@ -169,8 +134,8 @@ public function testDeclareBindShouldBindTopicToQueue()
169134
;
170135

171136
$context = new AmqpContext($connection, '');
172-
$context->bind($source, $target);
173-
$context->bind($target, $source);
137+
$context->bind(new AmqpBind($target, $source, 'routing-key', 12345));
138+
$context->bind(new AmqpBind($source, $target, 'routing-key', 12345));
174139
}
175140

176141
public function testShouldCloseChannelConnection()
@@ -194,16 +159,6 @@ public function testShouldCloseChannelConnection()
194159
$context->close();
195160
}
196161

197-
public function testPurgeShouldThrowExceptionIfDestinationIsNotAmqpQueue()
198-
{
199-
$context = new AmqpContext($this->createConnectionMock(), '');
200-
201-
$this->expectException(InvalidDestinationException::class);
202-
$this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpLib\AmqpQueue but got');
203-
204-
$context->purge(new NullQueue(''));
205-
}
206-
207162
public function testShouldPurgeQueue()
208163
{
209164
$queue = new AmqpQueue('queue');
@@ -223,7 +178,7 @@ public function testShouldPurgeQueue()
223178
;
224179

225180
$context = new AmqpContext($connection, '');
226-
$context->purge($queue);
181+
$context->purgeQueue($queue);
227182
}
228183

229184
/**

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
namespace Enqueue\AmqpLib\Tests;
44

5-
use Enqueue\AmqpLib\AmqpMessage;
65
use Enqueue\AmqpLib\AmqpProducer;
7-
use Enqueue\AmqpLib\AmqpQueue;
8-
use Enqueue\AmqpLib\AmqpTopic;
96
use Enqueue\Test\ClassExtensionTrait;
7+
use Interop\Amqp\Impl\AmqpMessage;
8+
use Interop\Amqp\Impl\AmqpQueue;
9+
use Interop\Amqp\Impl\AmqpTopic;
1010
use Interop\Queue\InvalidDestinationException;
1111
use Interop\Queue\InvalidMessageException;
1212
use Interop\Queue\PsrDestination;
@@ -36,7 +36,7 @@ public function testShouldThrowExceptionWhenDestinationTypeIsInvalid()
3636
$producer = new AmqpProducer($this->createAmqpChannelMock());
3737

3838
$this->expectException(InvalidDestinationException::class);
39-
$this->expectExceptionMessage('The destination must be an instance of Enqueue\AmqpLib\AmqpQueue but got');
39+
$this->expectExceptionMessage('The destination must be an instance of Interop\Amqp\AmqpQueue but got');
4040

4141
$producer->send($this->createDestinationMock(), new AmqpMessage());
4242
}
@@ -46,7 +46,7 @@ public function testShouldThrowExceptionWhenMessageTypeIsInvalid()
4646
$producer = new AmqpProducer($this->createAmqpChannelMock());
4747

4848
$this->expectException(InvalidMessageException::class);
49-
$this->expectExceptionMessage('The message must be an instance of Enqueue\AmqpLib\AmqpMessage but it is');
49+
$this->expectExceptionMessage('The message must be an instance of Interop\Amqp\AmqpMessage but it is');
5050

5151
$producer->send(new AmqpTopic('name'), $this->createMessageMock());
5252
}
@@ -66,10 +66,12 @@ public function testShouldPublishMessageToTopic()
6666
;
6767

6868
$topic = new AmqpTopic('topic');
69-
$topic->setRoutingKey('routing-key');
69+
70+
$message = new AmqpMessage('body');
71+
$message->setRoutingKey('routing-key');
7072

7173
$producer = new AmqpProducer($channel);
72-
$producer->send($topic, new AmqpMessage('body'));
74+
$producer->send($topic, $message);
7375

7476
$this->assertEquals('body', $amqpMessage->getBody());
7577
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Enqueue\AmqpLib\Tests;
44

5-
use Enqueue\AmqpLib\AmqpMessage;
65
use Enqueue\AmqpLib\Buffer;
6+
use Interop\Amqp\Impl\AmqpMessage;
77
use PHPUnit\Framework\TestCase;
88

99
class BufferTest extends TestCase

‎pkg/amqp-lib/Tests/Spec/AmqpMessageTest.php‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎pkg/amqp-lib/Tests/Spec/AmqpQueueTest.php‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎pkg/amqp-lib/Tests/Spec/AmqpSendToAndReceiveFromQueueTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function createQueue(PsrContext $context, $queueName)
3131
{
3232
$queue = $context->createQueue($queueName);
3333
$context->declareQueue($queue);
34-
$context->purge($queue);
34+
$context->purgeQueue($queue);
3535

3636
return $queue;
3737
}

‎pkg/amqp-lib/Tests/Spec/AmqpSendToAndReceiveFromTopicTest.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Enqueue\AmqpLib\AmqpConnectionFactory;
66
use Enqueue\AmqpLib\AmqpContext;
7+
use Interop\Amqp\AmqpTopic;
78
use Interop\Queue\PsrContext;
89
use Interop\Queue\Spec\SendToAndReceiveFromTopicSpec;
910

@@ -30,8 +31,8 @@ protected function createContext()
3031
protected function createTopic(PsrContext $context, $topicName)
3132
{
3233
$topic = $context->createTopic($topicName);
33-
$topic->setType('fanout');
34-
$topic->setDurable(true);
34+
$topic->setType(AmqpTopic::TYPE_FANOUT);
35+
$topic->addFlag(AmqpTopic::FLAG_DURABLE);
3536
$context->declareTopic($topic);
3637

3738
return $topic;

‎pkg/amqp-lib/Tests/Spec/AmqpSendToAndReceiveNoWaitFromQueueTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function createQueue(PsrContext $context, $queueName)
3131
{
3232
$queue = $context->createQueue($queueName);
3333
$context->declareQueue($queue);
34-
$context->purge($queue);
34+
$context->purgeQueue($queue);
3535

3636
return $queue;
3737
}

‎pkg/amqp-lib/Tests/Spec/AmqpSendToAndReceiveNoWaitFromTopicTest.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Enqueue\AmqpLib\AmqpConnectionFactory;
66
use Enqueue\AmqpLib\AmqpContext;
7+
use Interop\Amqp\AmqpTopic;
78
use Interop\Queue\PsrContext;
89
use Interop\Queue\Spec\SendToAndReceiveNoWaitFromTopicSpec;
910

@@ -30,8 +31,8 @@ protected function createContext()
3031
protected function createTopic(PsrContext $context, $topicName)
3132
{
3233
$topic = $context->createTopic($topicName);
33-
$topic->setType('fanout');
34-
$topic->setDurable(true);
34+
$topic->setType(AmqpTopic::TYPE_FANOUT);
35+
$topic->addFlag(AmqpTopic::FLAG_DURABLE);
3536
$context->declareTopic($topic);
3637

3738
return $topic;

0 commit comments

Comments
 (0)