@@ -53,6 +53,24 @@ public function testItCanBeConstructedWithDefaults()
53
53
);
54
54
}
55
55
56
+ public function testItCanBeConstructedWithAnAmqpsDsn ()
57
+ {
58
+ $ this ->assertEquals (
59
+ new Connection ([
60
+ 'host ' => 'localhost ' ,
61
+ 'port ' => 5671 ,
62
+ 'vhost ' => '/ ' ,
63
+ 'cacert ' => '/etc/ssl/certs ' ,
64
+ ], [
65
+ 'name ' => self ::DEFAULT_EXCHANGE_NAME ,
66
+ ], [
67
+ self ::DEFAULT_EXCHANGE_NAME => [],
68
+ ]),
69
+ Connection::fromDsn ('amqps://localhost? ' .
70
+ 'cacert=/etc/ssl/certs ' )
71
+ );
72
+ }
73
+
56
74
public function testItGetsParametersFromTheDsn ()
57
75
{
58
76
$ this ->assertEquals (
@@ -314,6 +332,45 @@ public function testItSetupsTheConnection()
314
332
$ connection ->publish ('body ' );
315
333
}
316
334
335
+ public function testItSetupsTheTTLConnection ()
336
+ {
337
+ $ amqpConnection = $ this ->createMock (\AMQPConnection::class);
338
+ $ amqpChannel = $ this ->createMock (\AMQPChannel::class);
339
+ $ amqpExchange = $ this ->createMock (\AMQPExchange::class);
340
+ $ amqpQueue0 = $ this ->createMock (\AMQPQueue::class);
341
+ $ amqpQueue1 = $ this ->createMock (\AMQPQueue::class);
342
+
343
+ $ factory = $ this ->createMock (AmqpFactory::class);
344
+ $ factory ->method ('createConnection ' )->willReturn ($ amqpConnection );
345
+ $ factory ->method ('createChannel ' )->willReturn ($ amqpChannel );
346
+ $ factory ->method ('createExchange ' )->willReturn ($ amqpExchange );
347
+ $ factory ->method ('createQueue ' )->will ($ this ->onConsecutiveCalls ($ amqpQueue0 , $ amqpQueue1 ));
348
+
349
+ $ amqpExchange ->expects ($ this ->once ())->method ('declareExchange ' );
350
+ $ amqpExchange ->expects ($ this ->once ())->method ('publish ' )->with ('body ' , 'routing_key ' , AMQP_NOPARAM , ['headers ' => [], 'delivery_mode ' => 2 , 'timestamp ' => time ()]);
351
+ $ amqpQueue0 ->expects ($ this ->once ())->method ('declareQueue ' );
352
+ $ amqpQueue0 ->expects ($ this ->exactly (2 ))->method ('bind ' )->withConsecutive (
353
+ [self ::DEFAULT_EXCHANGE_NAME , 'binding_key0 ' ],
354
+ [self ::DEFAULT_EXCHANGE_NAME , 'binding_key1 ' ]
355
+ );
356
+ $ amqpQueue1 ->expects ($ this ->once ())->method ('declareQueue ' );
357
+ $ amqpQueue1 ->expects ($ this ->exactly (2 ))->method ('bind ' )->withConsecutive (
358
+ [self ::DEFAULT_EXCHANGE_NAME , 'binding_key2 ' ],
359
+ [self ::DEFAULT_EXCHANGE_NAME , 'binding_key3 ' ]
360
+ );
361
+
362
+ $ dsn = 'amqps://localhost? ' .
363
+ 'cacert=/etc/ssl/certs& ' .
364
+ 'exchange[default_publish_routing_key]=routing_key& ' .
365
+ 'queues[queue0][binding_keys][0]=binding_key0& ' .
366
+ 'queues[queue0][binding_keys][1]=binding_key1& ' .
367
+ 'queues[queue1][binding_keys][0]=binding_key2& ' .
368
+ 'queues[queue1][binding_keys][1]=binding_key3 ' ;
369
+
370
+ $ connection = Connection::fromDsn ($ dsn , [], $ factory );
371
+ $ connection ->publish ('body ' );
372
+ }
373
+
317
374
public function testBindingArguments ()
318
375
{
319
376
$ amqpConnection = $ this ->createMock (\AMQPConnection::class);
@@ -506,6 +563,27 @@ public function testObfuscatePasswordInDsn()
506
563
$ connection ->channel ();
507
564
}
508
565
566
+ public function testNoCaCertOnSslConnectionFromDsn ()
567
+ {
568
+ $ this ->expectException (InvalidArgumentException::class);
569
+ $ this ->expectExceptionMessage ('No CA certificate has been provided. Set "amqp.cacert" in your php.ini or pass the "cacert" parameter in the DSN to use SSL. Alternatively, you can use amqp:// to use without SSL. ' );
570
+
571
+ $ factory = new TestAmqpFactory (
572
+ $ amqpConnection = $ this ->createMock (\AMQPConnection::class),
573
+ $ amqpChannel = $ this ->createMock (\AMQPChannel::class),
574
+ $ amqpQueue = $ this ->createMock (\AMQPQueue::class),
575
+ $ amqpExchange = $ this ->createMock (\AMQPExchange::class)
576
+ );
577
+
578
+ $ oldCaCertValue = ini_set ('amqp.cacert ' , '' );
579
+
580
+ try {
581
+ Connection::fromDsn ('amqps:// ' , [], $ factory );
582
+ } finally {
583
+ ini_set ('amqp.cacert ' , $ oldCaCertValue );
584
+ }
585
+ }
586
+
509
587
public function testAmqpStampHeadersAreUsed ()
510
588
{
511
589
$ factory = new TestAmqpFactory (
0 commit comments