Skip to content

Commit a5f3844

Browse files
committed
fix tests
1 parent 405c12d commit a5f3844

1 file changed

Lines changed: 19 additions & 35 deletions

File tree

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

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

55
use Enqueue\AmqpLib\AmqpConnectionFactory;
6-
use Enqueue\AmqpLib\AmqpContext;
76
use Interop\Amqp\AmqpTopic;
87
use Interop\Amqp\Impl\AmqpBind;
9-
use Interop\Queue\PsrContext;
8+
use Interop\Queue\PsrMessage;
109
use Interop\Queue\Spec\SendToTopicAndReceiveFromQueueSpec;
1110

1211
/**
@@ -26,50 +25,35 @@ protected function createContext()
2625
return $factory->createContext();
2726
}
2827

29-
/**
30-
* {@inheritdoc}
31-
*
32-
* @param AmqpContext $context
33-
*/
34-
protected function createQueue(PsrContext $context, $queueName)
28+
public function test()
3529
{
36-
$queueName .= '_basic_consume';
37-
38-
// $queue = $context->createQueue($queueName);
39-
$queue = $context->createQueue('send_to_topic_and_receive_from_queue_spec_basic_consume4');
30+
$context = $this->createContext();
4031

41-
try {
42-
$context->deleteQueue($queue);
43-
} catch (\Exception $e) {}
32+
$topic = $context->createTopic('send_to_topic_and_receive_from_queue_spec_basic_consume');
33+
$topic->setType(AmqpTopic::TYPE_FANOUT);
34+
$topic->addFlag(AmqpTopic::FLAG_DURABLE);
35+
$context->declareTopic($topic);
4436

37+
$queue = $context->createQueue('send_to_topic_and_receive_from_queue_spec_basic_consume');
4538
$context->declareQueue($queue);
4639
$context->purgeQueue($queue);
4740

48-
$context->bind(new AmqpBind($this->topic, $queue));
41+
$context->bind(new AmqpBind($topic, $queue));
4942

50-
return $queue;
51-
}
43+
$consumer = $context->createConsumer($queue);
5244

53-
/**
54-
* {@inheritdoc}
55-
*
56-
* @param AmqpContext $context
57-
*/
58-
protected function createTopic(PsrContext $context, $topicName)
59-
{
60-
$topicName .= '_basic_consume';
45+
// guard
46+
$this->assertNull($consumer->receiveNoWait());
6147

62-
// $topic = $context->createTopic($topicName);
63-
$topic = $context->createTopic('send_to_topic_and_receive_from_queue_spec_basic_consume4');
64-
$topic->setType(AmqpTopic::TYPE_FANOUT);
65-
$topic->addFlag(AmqpTopic::FLAG_DURABLE);
48+
$expectedBody = __CLASS__.time();
6649

67-
try {
68-
$context->deleteQueue($topic);
69-
} catch (\Exception $e) {}
50+
$context->createProducer()->send($topic, $context->createMessage($expectedBody));
7051

71-
$context->declareTopic($topic);
52+
$message = $consumer->receive(2000); // 2 sec
53+
54+
$this->assertInstanceOf(PsrMessage::class, $message);
55+
$consumer->acknowledge($message);
7256

73-
return $this->topic = $topic;
57+
$this->assertSame($expectedBody, $message->getBody());
7458
}
7559
}

0 commit comments

Comments
 (0)