@@ -246,15 +246,19 @@ public function testLazy()
246
246
$ connection = Connection::fromDsn ('redis://localhost/messenger-lazy?lazy=1 ' , ['delete_after_ack ' => true ], $ redis );
247
247
248
248
$ connection ->add ('1 ' , []);
249
- $ this ->assertNotEmpty ($ message = $ connection ->get ());
250
- $ this ->assertSame ([
251
- 'message ' => json_encode ([
252
- 'body ' => '1 ' ,
253
- 'headers ' => [],
254
- ]),
255
- ], $ message ['data ' ]);
256
- $ connection ->reject ($ message ['id ' ]);
257
- $ redis ->del ('messenger-lazy ' );
249
+
250
+ try {
251
+ $ this ->assertNotEmpty ($ message = $ connection ->get ());
252
+ $ this ->assertSame ([
253
+ 'message ' => json_encode ([
254
+ 'body ' => '1 ' ,
255
+ 'headers ' => [],
256
+ ]),
257
+ ], $ message ['data ' ]);
258
+ $ connection ->reject ($ message ['id ' ]);
259
+ } finally {
260
+ $ redis ->del ('messenger-lazy ' );
261
+ }
258
262
}
259
263
260
264
public function testDbIndex ()
@@ -283,13 +287,16 @@ public function testFromDsnWithMultipleHosts()
283
287
public function testJsonError ()
284
288
{
285
289
$ redis = new \Redis ();
286
- $ connection = Connection::fromDsn ('redis://localhost/json-error ' , ['delete_after_ack ' => true ], $ redis );
290
+ $ connection = Connection::fromDsn ('redis://localhost/messenger- json-error ' , ['delete_after_ack ' => true ], $ redis );
287
291
try {
288
292
$ connection ->add ("\xB1\x31" , []);
293
+
294
+ $ this ->fail ('Expected exception to be thrown. ' );
289
295
} catch (TransportException $ e ) {
296
+ $ this ->assertSame ('Malformed UTF-8 characters, possibly incorrectly encoded ' , $ e ->getMessage ());
297
+ } finally {
298
+ $ redis ->del ('messenger-json-error ' );
290
299
}
291
-
292
- $ this ->assertSame ('Malformed UTF-8 characters, possibly incorrectly encoded ' , $ e ->getMessage ());
293
300
}
294
301
295
302
public function testGetNonBlocking ()
@@ -298,28 +305,33 @@ public function testGetNonBlocking()
298
305
299
306
$ connection = Connection::fromDsn ('redis://localhost/messenger-getnonblocking ' , ['delete_after_ack ' => true ], $ redis );
300
307
301
- $ this ->assertNull ($ connection ->get ()); // no message, should return null immediately
302
- $ connection ->add ('1 ' , []);
303
- $ this ->assertNotEmpty ($ message = $ connection ->get ());
304
- $ connection ->reject ($ message ['id ' ]);
305
- $ redis ->del ('messenger-getnonblocking ' );
308
+ try {
309
+ $ this ->assertNull ($ connection ->get ()); // no message, should return null immediately
310
+ $ connection ->add ('1 ' , []);
311
+ $ this ->assertNotEmpty ($ message = $ connection ->get ());
312
+ $ connection ->reject ($ message ['id ' ]);
313
+ } finally {
314
+ $ redis ->del ('messenger-getnonblocking ' );
315
+ }
306
316
}
307
317
308
318
public function testGetAfterReject ()
309
319
{
310
320
$ redis = new \Redis ();
311
321
$ connection = Connection::fromDsn ('redis://localhost/messenger-rejectthenget ' , ['delete_after_ack ' => true ], $ redis );
312
322
313
- $ connection ->add ('1 ' , []);
314
- $ connection ->add ('2 ' , []);
315
-
316
- $ failing = $ connection ->get ();
317
- $ connection ->reject ($ failing ['id ' ]);
323
+ try {
324
+ $ connection ->add ('1 ' , []);
325
+ $ connection ->add ('2 ' , []);
318
326
319
- $ connection = Connection:: fromDsn ( ' redis://localhost/messenger-rejectthenget ' , [ ' delete_after_ack ' => true ] );
320
- $ this -> assertNotNull ( $ connection ->get () );
327
+ $ failing = $ connection -> get ( );
328
+ $ connection ->reject ( $ failing [ ' id ' ] );
321
329
322
- $ redis ->del ('messenger-rejectthenget ' );
330
+ $ connection = Connection::fromDsn ('redis://localhost/messenger-rejectthenget ' , ['delete_after_ack ' => true ]);
331
+ $ this ->assertNotNull ($ connection ->get ());
332
+ } finally {
333
+ $ redis ->del ('messenger-rejectthenget ' );
334
+ }
323
335
}
324
336
325
337
public function testItProperlyHandlesEmptyMessages ()
0 commit comments