33namespace Enqueue \AmqpLib \Tests \Spec ;
44
55use Enqueue \AmqpLib \AmqpConnectionFactory ;
6+ use Interop \Amqp \AmqpContext ;
67use Interop \Amqp \AmqpTopic ;
78use Interop \Amqp \Impl \AmqpBind ;
8- use Interop \Queue \PsrMessage ;
9+ use Interop \Queue \PsrContext ;
910use Interop \Queue \Spec \SendToTopicAndReceiveFromQueueSpec ;
1011
1112/**
@@ -25,20 +26,55 @@ protected function createContext()
2526 return $ factory ->createContext ();
2627 }
2728
28- public function test ()
29- {
30- $ context = $ this ->createContext ();
31-
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-
36- try {
37- $ context ->deleteTopic ($ topic );
38- } catch (\Exception $ e ) {}
39-
40- $ context ->declareTopic ($ topic );
29+ // public function test()
30+ // {
31+ // $context = $this->createContext();
32+ //
33+ // $topic = $context->createTopic('send_to_topic_and_receive_from_queue_spec_basic_consume');
34+ // $topic->setType(AmqpTopic::TYPE_FANOUT);
35+ // $topic->addFlag(AmqpTopic::FLAG_DURABLE);
36+ //
37+ // try {
38+ // $context->deleteTopic($topic);
39+ // } catch (\Exception $e) {}
40+ //
41+ // $context->declareTopic($topic);
42+ //
43+ // $queue = $context->createQueue('send_to_topic_and_receive_from_queue_spec_basic_consume');
44+ //
45+ // try {
46+ // $context->deleteQueue($queue);
47+ // } catch (\Exception $e) {}
48+ //
49+ // $context->declareQueue($queue);
50+ // $context->purgeQueue($queue);
51+ //
52+ // $context->bind(new AmqpBind($topic, $queue));
53+ //
54+ // $consumer = $context->createConsumer($queue);
55+ //
56+ // // guard
57+ // $this->assertNull($consumer->receiveNoWait());
58+ //
59+ // $expectedBody = __CLASS__.time();
60+ //
61+ // $context->createProducer()->send($topic, $context->createMessage($expectedBody));
62+ //
63+ // $message = $consumer->receive(2000); // 2 sec
64+ //
65+ // $this->assertInstanceOf(PsrMessage::class, $message);
66+ // $consumer->acknowledge($message);
67+ //
68+ // $this->assertSame($expectedBody, $message->getBody());
69+ // }
4170
71+ /**
72+ * {@inheritdoc}
73+ *
74+ * @param AmqpContext $context
75+ */
76+ protected function createQueue (PsrContext $ context , $ queueName )
77+ {
4278 $ queue = $ context ->createQueue ('send_to_topic_and_receive_from_queue_spec_basic_consume ' );
4379
4480 try {
@@ -48,22 +84,28 @@ public function test()
4884 $ context ->declareQueue ($ queue );
4985 $ context ->purgeQueue ($ queue );
5086
51- $ context ->bind (new AmqpBind ($ topic , $ queue ));
87+ $ context ->bind (new AmqpBind ($ this -> topic , $ queue ));
5288
53- $ consumer = $ context ->createConsumer ($ queue );
54-
55- // guard
56- $ this ->assertNull ($ consumer ->receiveNoWait ());
57-
58- $ expectedBody = __CLASS__ .time ();
89+ return $ queue ;
90+ }
5991
60- $ context ->createProducer ()->send ($ topic , $ context ->createMessage ($ expectedBody ));
92+ /**
93+ * {@inheritdoc}
94+ *
95+ * @param AmqpContext $context
96+ */
97+ protected function createTopic (PsrContext $ context , $ topicName )
98+ {
99+ $ topic = $ context ->createTopic ('send_to_topic_and_receive_from_queue_spec_basic_consume ' );
100+ $ topic ->setType (AmqpTopic::TYPE_FANOUT );
101+ $ topic ->addFlag (AmqpTopic::FLAG_DURABLE );
61102
62- $ message = $ consumer ->receive (2000 ); // 2 sec
103+ try {
104+ $ context ->deleteTopic ($ topic );
105+ } catch (\Exception $ e ) {}
63106
64- $ this ->assertInstanceOf (PsrMessage::class, $ message );
65- $ consumer ->acknowledge ($ message );
107+ $ context ->declareTopic ($ topic );
66108
67- $ this ->assertSame ( $ expectedBody , $ message -> getBody ()) ;
109+ return $ this ->topic = $ topic ;
68110 }
69111}
0 commit comments