@@ -393,7 +393,7 @@ public function testItSetupsTheTTLConnection()
393393 $ connection ->publish ('body ' );
394394 }
395395
396- public function testBindingArguments ()
396+ public function testQueueBindingArguments ()
397397 {
398398 $ amqpConnection = $ this ->createMock (\AMQPConnection::class);
399399 $ amqpChannel = $ this ->createMock (\AMQPChannel::class);
@@ -418,6 +418,62 @@ public function testBindingArguments()
418418 $ connection ->publish ('body ' );
419419 }
420420
421+ public function testExchangeBindingArguments ()
422+ {
423+ $ factory = new TestAmqpFactory (
424+ $ this ->createMock (\AMQPConnection::class),
425+ $ this ->createMock (\AMQPChannel::class),
426+ $ this ->createMock (\AMQPQueue::class),
427+ $ amqpExchange = $ this ->createMock (\AMQPExchange::class)
428+ );
429+
430+ $ amqpExchange ->expects ($ this ->once ())->method ('declareExchange ' );
431+ $ amqpExchange ->expects ($ this ->exactly (4 ))->method ('bind ' )
432+ ->willReturnCallback (function (...$ args ) {
433+ static $ series = [
434+ ['exchange0 ' , 'binding_key0 ' , ['x-match ' => 'all ' ]],
435+ ['exchange0 ' , 'binding_key1 ' , ['x-match ' => 'all ' ]],
436+ ['exchange1 ' , 'binding_key2 ' , ['x-match ' => 'any ' ]],
437+ ['exchange1 ' , 'binding_key3 ' , ['x-match ' => 'any ' ]],
438+ ];
439+
440+ $ expectedArgs = array_shift ($ series );
441+ $ this ->assertSame ($ expectedArgs , $ args );
442+ })
443+ ;
444+ $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , null , \AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 , 'timestamp ' => time ()]);
445+
446+ $ dsn = 'amqp://localhost?exchange[type]=headers ' .
447+ '&exchange[bindings][exchange0][binding_arguments][x-match]=all ' .
448+ '&exchange[bindings][exchange0][binding_keys][0]=binding_key0 ' .
449+ '&exchange[bindings][exchange0][binding_keys][1]=binding_key1 ' .
450+ '&exchange[bindings][exchange1][binding_arguments][x-match]=any ' .
451+ '&exchange[bindings][exchange1][binding_keys][0]=binding_key2 ' .
452+ '&exchange[bindings][exchange1][binding_keys][1]=binding_key3 ' ;
453+
454+ $ connection = Connection::fromDsn ($ dsn , [], $ factory );
455+ $ connection ->publish ('body ' );
456+ }
457+
458+ public function testNoBindingKeysInExchangeBindings ()
459+ {
460+ $ this ->expectException (\InvalidArgumentException::class);
461+ $ this ->expectExceptionMessage ('The "binding_keys" option must be set to a non-empty array for exchange "exchange0". ' );
462+
463+ $ factory = new TestAmqpFactory (
464+ $ this ->createMock (\AMQPConnection::class),
465+ $ this ->createMock (\AMQPChannel::class),
466+ $ this ->createMock (\AMQPQueue::class),
467+ $ this ->createMock (\AMQPExchange::class)
468+ );
469+
470+ $ dsn = 'amqp://localhost?exchange[type]=headers ' .
471+ '&exchange[bindings][exchange0][binding_arguments][x-match]=all ' ;
472+
473+ $ connection = Connection::fromDsn ($ dsn , [], $ factory );
474+ $ connection ->publish ('body ' );
475+ }
476+
421477 public function testItCanDisableTheSetup ()
422478 {
423479 $ factory = new TestAmqpFactory (
0 commit comments