33namespace Enqueue \AmqpLib \Tests ;
44
55use Enqueue \AmqpLib \AmqpContext ;
6- use Enqueue \AmqpLib \AmqpQueue ;
7- use Enqueue \AmqpLib \AmqpTopic ;
86use 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 ;
1110use Interop \Queue \InvalidDestinationException ;
1211use PhpAmqpLib \Channel \AMQPChannel ;
1312use 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 /**
0 commit comments