@@ -47,6 +47,7 @@ public function testFromDsn()
47
47
$ this ->assertSame ('default ' ,$ configuration ['tube_name ' ]);
48
48
$ this ->assertSame (0 ,$ configuration ['timeout ' ]);
49
49
$ this ->assertSame (90 ,$ configuration ['ttr ' ]);
50
+ $ this ->assertFalse ($ configuration ['bury_on_reject ' ]);
50
51
51
52
$ this ->assertEquals (
52
53
$ connection =new Connection ([], Pheanstalk::create ('foobar ' ,15555 )),
@@ -58,22 +59,32 @@ public function testFromDsn()
58
59
$ this ->assertSame ('default ' ,$ configuration ['tube_name ' ]);
59
60
$ this ->assertSame (0 ,$ configuration ['timeout ' ]);
60
61
$ this ->assertSame (90 ,$ configuration ['ttr ' ]);
62
+ $ this ->assertFalse ($ configuration ['bury_on_reject ' ]);
61
63
$ this ->assertSame ('default ' ,$ connection ->getTube ());
62
64
}
63
65
64
66
public function testFromDsnWithOptions ()
65
67
{
66
68
$ this ->assertEquals (
67
- $ connection = Connection::fromDsn ('beanstalkd://localhost ' , ['tube_name ' =>'foo ' ,'timeout ' =>10 ,'ttr ' =>5000 ]),
68
- Connection::fromDsn ('beanstalkd://localhost?tube_name=foo&timeout=10&ttr=5000 ' )
69
+ $ connectionWithOptions = Connection::fromDsn ('beanstalkd://localhost ' , ['tube_name ' =>'foo ' ,'timeout ' =>10 ,'ttr ' =>5000 , ' bury_on_reject ' => true ]),
70
+ $ connectionWithQuery = Connection::fromDsn ('beanstalkd://localhost?tube_name=foo&timeout=10&ttr=5000&bury_on_reject=true ' )
69
71
);
70
72
71
- $ configuration =$ connection ->getConfiguration ();
73
+ $ configuration =$ connectionWithOptions ->getConfiguration ();
72
74
73
75
$ this ->assertSame ('foo ' ,$ configuration ['tube_name ' ]);
74
76
$ this ->assertSame (10 ,$ configuration ['timeout ' ]);
75
77
$ this ->assertSame (5000 ,$ configuration ['ttr ' ]);
76
- $ this ->assertSame ('foo ' ,$ connection ->getTube ());
78
+ $ this ->assertTrue ($ configuration ['bury_on_reject ' ]);
79
+ $ this ->assertSame ('foo ' ,$ connectionWithOptions ->getTube ());
80
+
81
+ $ configuration =$ connectionWithQuery ->getConfiguration ();
82
+
83
+ $ this ->assertSame ('foo ' ,$ configuration ['tube_name ' ]);
84
+ $ this ->assertSame (10 ,$ configuration ['timeout ' ]);
85
+ $ this ->assertSame (5000 ,$ configuration ['ttr ' ]);
86
+ $ this ->assertTrue ($ configuration ['bury_on_reject ' ]);
87
+ $ this ->assertSame ('foo ' ,$ connectionWithOptions ->getTube ());
77
88
}
78
89
79
90
public function testFromDsnOptionsArrayWinsOverOptionsFromDsn ()
@@ -82,18 +93,20 @@ public function testFromDsnOptionsArrayWinsOverOptionsFromDsn()
82
93
'tube_name ' =>'bar ' ,
83
94
'timeout ' =>20 ,
84
95
'ttr ' =>6000 ,
96
+ 'bury_on_reject ' =>false ,
85
97
];
86
98
87
99
$ this ->assertEquals (
88
100
$ connection =new Connection ($ options , Pheanstalk::create ('localhost ' ,11333 )),
89
- Connection::fromDsn ('beanstalkd://localhost:11333?tube_name=foo&timeout=10&ttr=5000 ' ,$ options )
101
+ Connection::fromDsn ('beanstalkd://localhost:11333?tube_name=foo&timeout=10&ttr=5000&bury_on_reject=true ' ,$ options )
90
102
);
91
103
92
104
$ configuration =$ connection ->getConfiguration ();
93
105
94
106
$ this ->assertSame ($ options ['tube_name ' ],$ configuration ['tube_name ' ]);
95
107
$ this ->assertSame ($ options ['timeout ' ],$ configuration ['timeout ' ]);
96
108
$ this ->assertSame ($ options ['ttr ' ],$ configuration ['ttr ' ]);
109
+ $ this ->assertSame ($ options ['bury_on_reject ' ],$ configuration ['bury_on_reject ' ]);
97
110
$ this ->assertSame ($ options ['tube_name ' ],$ connection ->getTube ());
98
111
}
99
112
@@ -199,7 +212,12 @@ public function testAckWhenABeanstalkdExceptionOccurs()
199
212
$ connection ->ack ((string )$ id );
200
213
}
201
214
202
- public function testReject ()
215
+ /**
216
+ * @testWith [false, false]
217
+ * [false, true]
218
+ * [true, true]
219
+ */
220
+ public function testReject (bool $ buryOnReject ,bool $ forceDelete )
203
221
{
204
222
$ id =123456 ;
205
223
@@ -209,11 +227,42 @@ public function testReject()
209
227
$ client ->expects ($ this ->once ())->method ('useTube ' )->with ($ tube )->willReturn ($ client );
210
228
$ client ->expects ($ this ->once ())->method ('delete ' )->with ($ this ->callback (fn (JobId $ jobId ):bool =>$ jobId ->getId () ===$ id ));
211
229
212
- $ connection =new Connection (['tube_name ' =>$ tube ],$ client );
230
+ $ connection =new Connection (['tube_name ' =>$ tube ,'bury_on_reject ' =>$ buryOnReject ],$ client );
231
+
232
+ $ connection ->reject ((string )$ id ,null ,$ forceDelete );
233
+ }
234
+
235
+ public function testRejectWithBury ()
236
+ {
237
+ $ id =123456 ;
238
+
239
+ $ tube ='baz ' ;
240
+
241
+ $ client =$ this ->createMock (PheanstalkInterface::class);
242
+ $ client ->expects ($ this ->once ())->method ('useTube ' )->with ($ tube )->willReturn ($ client );
243
+ $ client ->expects ($ this ->once ())->method ('bury ' )->with ($ this ->callback (fn (JobId $ jobId ):bool =>$ jobId ->getId () ===$ id ),1024 );
244
+
245
+ $ connection =new Connection (['tube_name ' =>$ tube ,'bury_on_reject ' =>true ],$ client );
213
246
214
247
$ connection ->reject ((string )$ id );
215
248
}
216
249
250
+ public function testRejectWithBuryAndPriority ()
251
+ {
252
+ $ id =123456 ;
253
+ $ priority =2 ;
254
+
255
+ $ tube ='baz ' ;
256
+
257
+ $ client =$ this ->createMock (PheanstalkInterface::class);
258
+ $ client ->expects ($ this ->once ())->method ('useTube ' )->with ($ tube )->willReturn ($ client );
259
+ $ client ->expects ($ this ->once ())->method ('bury ' )->with ($ this ->callback (fn (JobId $ jobId ):bool =>$ jobId ->getId () ===$ id ),$ priority );
260
+
261
+ $ connection =new Connection (['tube_name ' =>$ tube ,'bury_on_reject ' =>true ],$ client );
262
+
263
+ $ connection ->reject ((string )$ id ,$ priority );
264
+ }
265
+
217
266
public function testRejectWhenABeanstalkdExceptionOccurs ()
218
267
{
219
268
$ id =123456 ;
@@ -263,6 +312,40 @@ public function testMessageCountWhenABeanstalkdExceptionOccurs()
263
312
$ connection ->getMessageCount ();
264
313
}
265
314
315
+ public function testMessagePriority ()
316
+ {
317
+ $ id =123456 ;
318
+ $ priority =51 ;
319
+
320
+ $ tube ='baz ' ;
321
+
322
+ $ response =new ArrayResponse ('OK ' , ['pri ' =>$ priority ]);
323
+
324
+ $ client =$ this ->createMock (PheanstalkInterface::class);
325
+ $ client ->expects ($ this ->once ())->method ('statsJob ' )->with ($ this ->callback (fn (JobId $ jobId ):bool =>$ jobId ->getId () ===$ id ))->willReturn ($ response );
326
+
327
+ $ connection =new Connection (['tube_name ' =>$ tube ],$ client );
328
+
329
+ $ this ->assertSame ($ priority ,$ connection ->getMessagePriority ((string )$ id ));
330
+ }
331
+
332
+ public function testMessagePriorityWhenABeanstalkdExceptionOccurs ()
333
+ {
334
+ $ id =123456 ;
335
+
336
+ $ tube ='baz1234 ' ;
337
+
338
+ $ exception =new ClientException ('foobar error ' );
339
+
340
+ $ client =$ this ->createMock (PheanstalkInterface::class);
341
+ $ client ->expects ($ this ->once ())->method ('statsJob ' )->with ($ this ->callback (fn (JobId $ jobId ):bool =>$ jobId ->getId () ===$ id ))->willThrowException ($ exception );
342
+
343
+ $ connection =new Connection (['tube_name ' =>$ tube ],$ client );
344
+
345
+ $ this ->expectExceptionObject (new TransportException ($ exception ->getMessage (),0 ,$ exception ));
346
+ $ connection ->getMessagePriority ((string )$ id );
347
+ }
348
+
266
349
public function testSend ()
267
350
{
268
351
$ tube ='xyz ' ;