@@ -47,6 +47,8 @@ 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 ->assertSame (PheanstalkInterface::DEFAULT_PRIORITY , $ configuration ['priority ' ]);
51
+ $ this ->assertFalse ($ configuration ['bury_on_reject ' ]);
50
52
51
53
$ this ->assertEquals (
52
54
$ connection = new Connection ([], Pheanstalk::create ('foobar ' , 15555 )),
@@ -58,22 +60,35 @@ public function testFromDsn()
58
60
$ this ->assertSame ('default ' , $ configuration ['tube_name ' ]);
59
61
$ this ->assertSame (0 , $ configuration ['timeout ' ]);
60
62
$ this ->assertSame (90 , $ configuration ['ttr ' ]);
63
+ $ this ->assertSame (PheanstalkInterface::DEFAULT_PRIORITY , $ configuration ['priority ' ]);
64
+ $ this ->assertFalse ($ configuration ['bury_on_reject ' ]);
61
65
$ this ->assertSame ('default ' , $ connection ->getTube ());
62
66
}
63
67
64
68
public function testFromDsnWithOptions ()
65
69
{
66
70
$ 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 ' )
71
+ $ connectionWithOptions = Connection::fromDsn ('beanstalkd://localhost ' , ['tube_name ' => 'foo ' , 'timeout ' => 10 , 'ttr ' => 5000 , ' priority ' => 300 , ' bury_on_reject ' => true ]),
72
+ $ connectionWithQuery = Connection::fromDsn ('beanstalkd://localhost?tube_name=foo&timeout=10&ttr=5000&priority=300&bury_on_reject=true ' )
69
73
);
70
74
71
- $ configuration = $ connection ->getConfiguration ();
75
+ $ configuration = $ connectionWithOptions ->getConfiguration ();
76
+
77
+ $ this ->assertSame ('foo ' , $ configuration ['tube_name ' ]);
78
+ $ this ->assertSame (10 , $ configuration ['timeout ' ]);
79
+ $ this ->assertSame (5000 , $ configuration ['ttr ' ]);
80
+ $ this ->assertSame (300 , $ configuration ['priority ' ]);
81
+ $ this ->assertTrue ($ configuration ['bury_on_reject ' ]);
82
+ $ this ->assertSame ('foo ' , $ connectionWithOptions ->getTube ());
83
+
84
+ $ configuration = $ connectionWithQuery ->getConfiguration ();
72
85
73
86
$ this ->assertSame ('foo ' , $ configuration ['tube_name ' ]);
74
87
$ this ->assertSame (10 , $ configuration ['timeout ' ]);
75
88
$ this ->assertSame (5000 , $ configuration ['ttr ' ]);
76
- $ this ->assertSame ('foo ' , $ connection ->getTube ());
89
+ $ this ->assertSame (300 , $ configuration ['priority ' ]);
90
+ $ this ->assertTrue ($ configuration ['bury_on_reject ' ]);
91
+ $ this ->assertSame ('foo ' , $ connectionWithOptions ->getTube ());
77
92
}
78
93
79
94
public function testFromDsnOptionsArrayWinsOverOptionsFromDsn ()
@@ -82,18 +97,22 @@ public function testFromDsnOptionsArrayWinsOverOptionsFromDsn()
82
97
'tube_name ' => 'bar ' ,
83
98
'timeout ' => 20 ,
84
99
'ttr ' => 6000 ,
100
+ 'priority ' => 300 ,
101
+ 'bury_on_reject ' => false ,
85
102
];
86
103
87
104
$ this ->assertEquals (
88
105
$ connection = new Connection ($ options , Pheanstalk::create ('localhost ' , 11333 )),
89
- Connection::fromDsn ('beanstalkd://localhost:11333?tube_name=foo&timeout=10&ttr=5000 ' , $ options )
106
+ Connection::fromDsn ('beanstalkd://localhost:11333?tube_name=foo&timeout=10&ttr=5000&priority=500&bury_on_reject=true ' , $ options )
90
107
);
91
108
92
109
$ configuration = $ connection ->getConfiguration ();
93
110
94
111
$ this ->assertSame ($ options ['tube_name ' ], $ configuration ['tube_name ' ]);
95
112
$ this ->assertSame ($ options ['timeout ' ], $ configuration ['timeout ' ]);
96
113
$ this ->assertSame ($ options ['ttr ' ], $ configuration ['ttr ' ]);
114
+ $ this ->assertSame ($ options ['priority ' ], $ configuration ['priority ' ]);
115
+ $ this ->assertSame ($ options ['bury_on_reject ' ], $ configuration ['bury_on_reject ' ]);
97
116
$ this ->assertSame ($ options ['tube_name ' ], $ connection ->getTube ());
98
117
}
99
118
@@ -214,6 +233,22 @@ public function testReject()
214
233
$ connection ->reject ((string ) $ id );
215
234
}
216
235
236
+ public function testRejectWithBury ()
237
+ {
238
+ $ id = 123456 ;
239
+
240
+ $ tube = 'baz ' ;
241
+ $ priority = 300 ;
242
+
243
+ $ client = $ this ->createMock (PheanstalkInterface::class);
244
+ $ client ->expects ($ this ->once ())->method ('useTube ' )->with ($ tube )->willReturn ($ client );
245
+ $ client ->expects ($ this ->once ())->method ('bury ' )->with ($ this ->callback (fn (JobId $ jobId ): bool => $ jobId ->getId () === $ id ), $ priority );
246
+
247
+ $ connection = new Connection (['tube_name ' => $ tube , 'priority ' => $ priority , 'bury_on_reject ' => true ], $ client );
248
+
249
+ $ connection ->reject ((string ) $ id );
250
+ }
251
+
217
252
public function testRejectWhenABeanstalkdExceptionOccurs ()
218
253
{
219
254
$ id = 123456 ;
@@ -266,6 +301,7 @@ public function testMessageCountWhenABeanstalkdExceptionOccurs()
266
301
public function testSend ()
267
302
{
268
303
$ tube = 'xyz ' ;
304
+ $ priority = 300 ;
269
305
270
306
$ body = 'foo ' ;
271
307
$ headers = ['test ' => 'bar ' ];
@@ -285,12 +321,12 @@ public function testSend()
285
321
286
322
return $ expectedMessage === $ data ;
287
323
}),
288
- 1024 ,
324
+ $ priority ,
289
325
$ expectedDelay ,
290
326
90
291
327
)->willReturn (new Job ($ id , 'foobar ' ));
292
328
293
- $ connection = new Connection (['tube_name ' => $ tube ], $ client );
329
+ $ connection = new Connection (['tube_name ' => $ tube, ' priority ' => $ priority ], $ client );
294
330
295
331
$ returnedId = $ connection ->send ($ body , $ headers , $ delay );
296
332
0 commit comments