12
12
namespace Symfony \Component \Messenger \Tests \Transport \AmqpExt ;
13
13
14
14
use PHPUnit \Framework \TestCase ;
15
+ use Symfony \Component \Messenger \Exception \InvalidArgumentException ;
15
16
use Symfony \Component \Messenger \Transport \AmqpExt \AmqpFactory ;
16
17
use Symfony \Component \Messenger \Transport \AmqpExt \Connection ;
17
18
@@ -96,17 +97,30 @@ public function testSetsParametersOnTheQueueAndExchange()
96
97
97
98
$ amqpQueue ->expects ($ this ->once ())->method ('setArguments ' )->with ([
98
99
'x-dead-letter-exchange ' => 'dead-exchange ' ,
99
- 'x-message-ttl ' => '1200 ' ,
100
+ 'x-delay ' => 100 ,
101
+ 'x-expires ' => 150 ,
102
+ 'x-max-length ' => 200 ,
103
+ 'x-max-length-bytes ' => 300 ,
104
+ 'x-max-priority ' => 4 ,
105
+ 'x-message-ttl ' => 100 ,
100
106
]);
101
107
102
108
$ amqpExchange ->expects ($ this ->once ())->method ('setArguments ' )->with ([
103
109
'alternate-exchange ' => 'alternate ' ,
104
110
]);
105
111
106
- $ connection = Connection::fromDsn ('amqp://localhost/%2f/messages?queue[arguments][x-dead-letter-exchange]=dead-exchange ' , [
112
+ $ dsn = 'amqp://localhost/%2f/messages? ' .
113
+ 'queue[arguments][x-dead-letter-exchange]=dead-exchange& ' .
114
+ 'queue[arguments][x-message-ttl]=100& ' .
115
+ 'queue[arguments][x-delay]=100& ' .
116
+ 'queue[arguments][x-expires]=150& '
117
+ ;
118
+ $ connection = Connection::fromDsn ($ dsn , [
107
119
'queue ' => [
108
120
'arguments ' => [
109
- 'x-message-ttl ' => '1200 ' ,
121
+ 'x-max-length ' => '200 ' ,
122
+ 'x-max-length-bytes ' => '300 ' ,
123
+ 'x-max-priority ' => '4 ' ,
110
124
],
111
125
],
112
126
'exchange ' => [
@@ -118,6 +132,36 @@ public function testSetsParametersOnTheQueueAndExchange()
118
132
$ connection ->publish ('body ' );
119
133
}
120
134
135
+ public function invalidQueueArgumentsDataProvider (): iterable
136
+ {
137
+ $ baseDsn = 'amqp://localhost/%2f/messages ' ;
138
+ yield [$ baseDsn .'?queue[arguments][x-delay]=not-a-number ' , []];
139
+ yield [$ baseDsn .'?queue[arguments][x-expires]=not-a-number ' , []];
140
+ yield [$ baseDsn .'?queue[arguments][x-max-length]=not-a-number ' , []];
141
+ yield [$ baseDsn .'?queue[arguments][x-max-length-bytes]=not-a-number ' , []];
142
+ yield [$ baseDsn .'?queue[arguments][x-max-priority]=not-a-number ' , []];
143
+ yield [$ baseDsn .'?queue[arguments][x-message-ttl]=not-a-number ' , []];
144
+
145
+ // Ensure the exception is thrown when the arguments are passed via the array options
146
+ yield [$ baseDsn , ['queue ' => ['arguments ' => ['x-delay ' => 'not-a-number ' ]]]];
147
+ yield [$ baseDsn , ['queue ' => ['arguments ' => ['x-expires ' => 'not-a-number ' ]]]];
148
+ yield [$ baseDsn , ['queue ' => ['arguments ' => ['x-max-length ' => 'not-a-number ' ]]]];
149
+ yield [$ baseDsn , ['queue ' => ['arguments ' => ['x-max-length-bytes ' => 'not-a-number ' ]]]];
150
+ yield [$ baseDsn , ['queue ' => ['arguments ' => ['x-max-priority ' => 'not-a-number ' ]]]];
151
+ yield [$ baseDsn , ['queue ' => ['arguments ' => ['x-message-ttl ' => 'not-a-number ' ]]]];
152
+ }
153
+
154
+ /**
155
+ * @dataProvider invalidQueueArgumentsDataProvider
156
+ */
157
+ public function testFromDsnWithInvalidValueOnQueueArguments (string $ dsn , array $ options )
158
+ {
159
+ $ this ->expectException (InvalidArgumentException::class);
160
+ $ this ->expectExceptionMessage ('Integer expected for queue argument ' );
161
+
162
+ Connection::fromDsn ($ dsn , $ options );
163
+ }
164
+
121
165
public function testItUsesANormalConnectionByDefault ()
122
166
{
123
167
$ factory = new TestAmqpFactory (
0 commit comments