12
12
namespace Symfony \Component \Messenger \Bridge \Amqp \Tests \Transport ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Bridge \PhpUnit \ClockMock ;
15
16
use Symfony \Bridge \PhpUnit \ExpectDeprecationTrait ;
16
17
use Symfony \Component \Messenger \Bridge \Amqp \Tests \Fixtures \DummyMessage ;
17
18
use Symfony \Component \Messenger \Bridge \Amqp \Transport \AmqpFactory ;
21
22
22
23
/**
23
24
* @requires extension amqp
25
+ *
26
+ * @group time-sensitive
24
27
*/
25
28
class ConnectionTest extends TestCase
26
29
{
@@ -266,7 +269,7 @@ public function testItSetupsTheConnectionWithDefaults()
266
269
);
267
270
268
271
$ 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 () ]);
270
273
$ amqpQueue ->expects ($ this ->once ())->method ('declareQueue ' );
271
274
$ amqpQueue ->expects ($ this ->once ())->method ('bind ' )->with (self ::DEFAULT_EXCHANGE_NAME , null );
272
275
@@ -289,7 +292,7 @@ public function testItSetupsTheConnection()
289
292
$ factory ->method ('createQueue ' )->will ($ this ->onConsecutiveCalls ($ amqpQueue0 , $ amqpQueue1 ));
290
293
291
294
$ 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 () ]);
293
296
$ amqpQueue0 ->expects ($ this ->once ())->method ('declareQueue ' );
294
297
$ amqpQueue0 ->expects ($ this ->exactly (2 ))->method ('bind ' )->withConsecutive (
295
298
[self ::DEFAULT_EXCHANGE_NAME , 'binding_key0 ' ],
@@ -326,7 +329,7 @@ public function testBindingArguments()
326
329
$ factory ->method ('createQueue ' )->willReturn ($ amqpQueue );
327
330
328
331
$ 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 () ]);
330
333
$ amqpQueue ->expects ($ this ->once ())->method ('declareQueue ' );
331
334
$ amqpQueue ->expects ($ this ->exactly (1 ))->method ('bind ' )->withConsecutive (
332
335
[self ::DEFAULT_EXCHANGE_NAME , null , ['x-match ' => 'all ' ]]
@@ -439,7 +442,7 @@ public function testItDelaysTheMessage()
439
442
$ delayQueue ->expects ($ this ->once ())->method ('declareQueue ' );
440
443
$ delayQueue ->expects ($ this ->once ())->method ('bind ' )->with ('delays ' , 'delay_messages__5000 ' );
441
444
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 () ]);
443
446
444
447
$ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
445
448
$ connection ->publish ('{} ' , ['x-some-headers ' => 'foo ' ], 5000 );
@@ -481,7 +484,7 @@ public function testItDelaysTheMessageWithADifferentRoutingKeyAndTTLs()
481
484
$ delayQueue ->expects ($ this ->once ())->method ('declareQueue ' );
482
485
$ delayQueue ->expects ($ this ->once ())->method ('bind ' )->with ('delays ' , 'delay_messages__120000 ' );
483
486
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 () ]);
485
488
$ connection ->publish ('{} ' , [], 120000 );
486
489
}
487
490
@@ -513,7 +516,7 @@ public function testAmqpStampHeadersAreUsed()
513
516
$ amqpExchange = $ this ->createMock (\AMQPExchange::class)
514
517
);
515
518
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 () ]);
517
520
518
521
$ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
519
522
$ connection ->publish ('body ' , ['Foo ' => 'X ' ], 0 , new AmqpStamp (null , AMQP_NOPARAM , ['headers ' => ['Bar ' => 'Y ' ]]));
@@ -528,7 +531,7 @@ public function testAmqpStampDelireryModeIsUsed()
528
531
$ amqpExchange = $ this ->createMock (\AMQPExchange::class)
529
532
);
530
533
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 () ]);
532
535
533
536
$ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
534
537
$ connection ->publish ('body ' , [], 0 , new AmqpStamp (null , AMQP_NOPARAM , ['delivery_mode ' => 1 ]));
@@ -600,7 +603,7 @@ public function testItDelaysTheMessageWithTheInitialSuppliedRoutingKeyAsArgument
600
603
$ delayQueue ->expects ($ this ->once ())->method ('declareQueue ' );
601
604
$ delayQueue ->expects ($ this ->once ())->method ('bind ' )->with ('delays ' , 'delay_messages_routing_key_120000 ' );
602
605
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 () ]);
604
607
$ connection ->publish ('{} ' , [], 120000 , new AmqpStamp ('routing_key ' ));
605
608
}
606
609
@@ -617,7 +620,7 @@ public function testItCanPublishWithCustomFlagsAndAttributes()
617
620
'body ' ,
618
621
'routing_key ' ,
619
622
AMQP_IMMEDIATE ,
620
- ['delivery_mode ' => 2 , 'headers ' => ['type ' => DummyMessage::class]]
623
+ ['delivery_mode ' => 2 , 'headers ' => ['type ' => DummyMessage::class], ' timestamp ' => time () ]
621
624
);
622
625
623
626
$ connection = Connection::fromDsn ('amqp://localhost ' , [], $ factory );
0 commit comments