@@ -47,6 +47,7 @@ public function testFromDsn()
4747 $ this ->assertSame ('default ' , $ configuration ['tube_name ' ]);
4848 $ this ->assertSame (0 , $ configuration ['timeout ' ]);
4949 $ this ->assertSame (90 , $ configuration ['ttr ' ]);
50+ $ this ->assertFalse ($ configuration ['bury_on_reject ' ]);
5051
5152 $ this ->assertEquals (
5253 $ connection = new Connection ([], Pheanstalk::create ('foobar ' , 15555 )),
@@ -58,22 +59,32 @@ public function testFromDsn()
5859 $ this ->assertSame ('default ' , $ configuration ['tube_name ' ]);
5960 $ this ->assertSame (0 , $ configuration ['timeout ' ]);
6061 $ this ->assertSame (90 , $ configuration ['ttr ' ]);
62+ $ this ->assertFalse ($ configuration ['bury_on_reject ' ]);
6163 $ this ->assertSame ('default ' , $ connection ->getTube ());
6264 }
6365
6466 public function testFromDsnWithOptions ()
6567 {
6668 $ 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 ' )
6971 );
7072
71- $ configuration = $ connection ->getConfiguration ();
73+ $ configuration = $ connectionWithOptions ->getConfiguration ();
7274
7375 $ this ->assertSame ('foo ' , $ configuration ['tube_name ' ]);
7476 $ this ->assertSame (10 , $ configuration ['timeout ' ]);
7577 $ 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 ());
7788 }
7889
7990 public function testFromDsnOptionsArrayWinsOverOptionsFromDsn ()
@@ -82,18 +93,20 @@ public function testFromDsnOptionsArrayWinsOverOptionsFromDsn()
8293 'tube_name ' => 'bar ' ,
8394 'timeout ' => 20 ,
8495 'ttr ' => 6000 ,
96+ 'bury_on_reject ' => false ,
8597 ];
8698
8799 $ this ->assertEquals (
88100 $ 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 )
90102 );
91103
92104 $ configuration = $ connection ->getConfiguration ();
93105
94106 $ this ->assertSame ($ options ['tube_name ' ], $ configuration ['tube_name ' ]);
95107 $ this ->assertSame ($ options ['timeout ' ], $ configuration ['timeout ' ]);
96108 $ this ->assertSame ($ options ['ttr ' ], $ configuration ['ttr ' ]);
109+ $ this ->assertSame ($ options ['bury_on_reject ' ], $ configuration ['bury_on_reject ' ]);
97110 $ this ->assertSame ($ options ['tube_name ' ], $ connection ->getTube ());
98111 }
99112
@@ -199,7 +212,12 @@ public function testAckWhenABeanstalkdExceptionOccurs()
199212 $ connection ->ack ((string ) $ id );
200213 }
201214
202- public function testReject ()
215+ /**
216+ * @testWith [false, false]
217+ * [false, true]
218+ * [true, true]
219+ */
220+ public function testReject (bool $ buryOnReject , bool $ forceDelete )
203221 {
204222 $ id = 123456 ;
205223
@@ -209,11 +227,42 @@ public function testReject()
209227 $ client ->expects ($ this ->once ())->method ('useTube ' )->with ($ tube )->willReturn ($ client );
210228 $ client ->expects ($ this ->once ())->method ('delete ' )->with ($ this ->callback (fn (JobId $ jobId ): bool => $ jobId ->getId () === $ id ));
211229
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 );
213246
214247 $ connection ->reject ((string ) $ id );
215248 }
216249
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+
217266 public function testRejectWhenABeanstalkdExceptionOccurs ()
218267 {
219268 $ id = 123456 ;
@@ -263,6 +312,40 @@ public function testMessageCountWhenABeanstalkdExceptionOccurs()
263312 $ connection ->getMessageCount ();
264313 }
265314
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+
266349 public function testSend ()
267350 {
268351 $ tube = 'xyz ' ;
0 commit comments