1212namespace Symfony \Component \Messenger \Bridge \Amqp \Tests \Transport ;
1313
1414use PHPUnit \Framework \TestCase ;
15+ use Symfony \Bridge \PhpUnit \ClockMock ;
1516use Symfony \Bridge \PhpUnit \ExpectDeprecationTrait ;
1617use Symfony \Component \Messenger \Bridge \Amqp \Tests \Fixtures \DummyMessage ;
1718use Symfony \Component \Messenger \Bridge \Amqp \Transport \AmqpFactory ;
2122
2223/**
2324 * @requires extension amqp
25+ *
26+ * @group time-sensitive
2427 */
2528class ConnectionTest extends TestCase
2629{
@@ -266,7 +269,7 @@ public function testItSetupsTheConnectionWithDefaults()
266269 );
267270
268271 $ amqpExchange ->expects ($ this ->once ())->method ('declareExchange ' );
269- $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , null , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 ]);
272+ $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , null , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 , ' timestamp ' => time () ]);
270273 $ amqpQueue ->expects ($ this ->once ())->method ('declareQueue ' );
271274 $ amqpQueue ->expects ($ this ->once ())->method ('bind ' )->with (self ::DEFAULT_EXCHANGE_NAME , null );
272275
@@ -289,7 +292,7 @@ public function testItSetupsTheConnection()
289292 $ factory ->method ('createQueue ' )->will ($ this ->onConsecutiveCalls ($ amqpQueue0 , $ amqpQueue1 ));
290293
291294 $ amqpExchange ->expects ($ this ->once ())->method ('declareExchange ' );
292- $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , 'routing_key ' , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 ]);
295+ $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , 'routing_key ' , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 , ' timestamp ' => time () ]);
293296 $ amqpQueue0 ->expects ($ this ->once ())->method ('declareQueue ' );
294297 $ amqpQueue0 ->expects ($ this ->exactly (2 ))->method ('bind ' )->withConsecutive (
295298 [self ::DEFAULT_EXCHANGE_NAME , 'binding_key0 ' ],
@@ -326,7 +329,7 @@ public function testBindingArguments()
326329 $ factory ->method ('createQueue ' )->willReturn ($ amqpQueue );
327330
328331 $ amqpExchange ->expects ($ this ->once ())->method ('declareExchange ' );
329- $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , null , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 ]);
332+ $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , null , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 , ' timestamp ' => time () ]);
330333 $ amqpQueue ->expects ($ this ->once ())->method ('declareQueue ' );
331334 $ amqpQueue ->expects ($ this ->exactly (1 ))->method ('bind ' )->withConsecutive (
332335 [self ::DEFAULT_EXCHANGE_NAME , null , ['x-match ' => 'all ' ]]
@@ -439,7 +442,7 @@ public function testItDelaysTheMessage()
439442 $ delayQueue ->expects ($ this ->once ())->method ('declareQueue ' );
440443 $ delayQueue ->expects ($ this ->once ())->method ('bind ' )->with ('delays ' , 'delay_messages__5000 ' );
441444
442- $ delayExchange ->expects ($ this ->once ())->method ('publish ' )->with ('{} ' , 'delay_messages__5000 ' , AMQP_NOPARAM , ['headers ' => ['x-some-headers ' => 'foo ' ], 'delivery_mode ' => 2 ]);
445+ $ delayExchange ->expects ($ this ->once ())->method ('publish ' )->with ('{} ' , 'delay_messages__5000 ' , AMQP_NOPARAM , ['headers ' => ['x-some-headers ' => 'foo ' ], 'delivery_mode ' => 2 , ' timestamp ' => time () ]);
443446
444447 $ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
445448 $ connection ->publish ('{} ' , ['x-some-headers ' => 'foo ' ], 5000 );
@@ -481,7 +484,7 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs()
481484 $ delayQueue ->expects ($ this ->once ())->method ('declareQueue ' );
482485 $ delayQueue ->expects ($ this ->once ())->method ('bind ' )->with ('delays ' , 'delay_messages__120000 ' );
483486
484- $ delayExchange ->expects ($ this ->once ())->method ('publish ' )->with ('{} ' , 'delay_messages__120000 ' , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 ]);
487+ $ delayExchange ->expects ($ this ->once ())->method ('publish ' )->with ('{} ' , 'delay_messages__120000 ' , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 , ' timestamp ' => time () ]);
485488 $ connection ->publish ('{} ' , [], 120000 );
486489 }
487490
@@ -513,7 +516,7 @@ public function testAmqpStampHeadersAreUsed()
513516 $ amqpExchange = $ this ->createMock (\AMQPExchange::class)
514517 );
515518
516- $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , null , AMQP_NOPARAM , ['headers ' => ['Foo ' => 'X ' , 'Bar ' => 'Y ' ], 'delivery_mode ' => 2 ]);
519+ $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , null , AMQP_NOPARAM , ['headers ' => ['Foo ' => 'X ' , 'Bar ' => 'Y ' ], 'delivery_mode ' => 2 , ' timestamp ' => time () ]);
517520
518521 $ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
519522 $ connection ->publish ('body ' , ['Foo ' => 'X ' ], 0 , new AmqpStamp (null , AMQP_NOPARAM , ['headers ' => ['Bar ' => 'Y ' ]]));
@@ -528,7 +531,7 @@ public function testAmqpStampDelireryModeIsUsed()
528531 $ amqpExchange = $ this ->createMock (\AMQPExchange::class)
529532 );
530533
531- $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , null , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 1 ]);
534+ $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , null , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 1 , ' timestamp ' => time () ]);
532535
533536 $ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
534537 $ connection ->publish ('body ' , [], 0 , new AmqpStamp (null , AMQP_NOPARAM , ['delivery_mode ' => 1 ]));
@@ -600,7 +603,7 @@ public function testItDelaysTheMessageWithTheInitialSuppliedRoutingKeyAsArgument
600603 $ delayQueue ->expects ($ this ->once ())->method ('declareQueue ' );
601604 $ delayQueue ->expects ($ this ->once ())->method ('bind ' )->with ('delays ' , 'delay_messages_routing_key_120000 ' );
602605
603- $ delayExchange ->expects ($ this ->once ())->method ('publish ' )->with ('{} ' , 'delay_messages_routing_key_120000 ' , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 ]);
606+ $ delayExchange ->expects ($ this ->once ())->method ('publish ' )->with ('{} ' , 'delay_messages_routing_key_120000 ' , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 , ' timestamp ' => time () ]);
604607 $ connection ->publish ('{} ' , [], 120000 , new AmqpStamp ('routing_key ' ));
605608 }
606609
@@ -617,7 +620,7 @@ public function testItCanPublishWithCustomFlagsAndAttributes()
617620 'body ' ,
618621 'routing_key ' ,
619622 AMQP_IMMEDIATE ,
620- ['delivery_mode ' => 2 , 'headers ' => ['type ' => DummyMessage::class]]
623+ ['delivery_mode ' => 2 , 'headers ' => ['type ' => DummyMessage::class], ' timestamp ' => time () ]
621624 );
622625
623626 $ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
0 commit comments