Skip to content

Commit 092f374

Browse files
committed
minor symfony#52991 [Messenger] Add missing Redis cleanup in tests (alexandre-daubois)
This PR was merged into the 5.4 branch. Discussion ---------- [Messenger] Add missing Redis cleanup in tests | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT This cleanup is present in all tests of this file but this one. Commits ------- 94461f9 [Messenger] Add missing Redis cleanup in tests
2 parents fa23eb6 + 94461f9 commit 092f374

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/RedisExtIntegrationTest.php

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,19 @@ public function testLazy()
246246
$connection = Connection::fromDsn('redis://localhost/messenger-lazy?lazy=1', ['delete_after_ack' => true], $redis);
247247

248248
$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+
}
258262
}
259263

260264
public function testDbIndex()
@@ -283,13 +287,16 @@ public function testFromDsnWithMultipleHosts()
283287
public function testJsonError()
284288
{
285289
$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);
287291
try {
288292
$connection->add("\xB1\x31", []);
293+
294+
$this->fail('Expected exception to be thrown.');
289295
} catch (TransportException $e) {
296+
$this->assertSame('Malformed UTF-8 characters, possibly incorrectly encoded', $e->getMessage());
297+
} finally {
298+
$redis->del('messenger-json-error');
290299
}
291-
292-
$this->assertSame('Malformed UTF-8 characters, possibly incorrectly encoded', $e->getMessage());
293300
}
294301

295302
public function testGetNonBlocking()
@@ -298,28 +305,33 @@ public function testGetNonBlocking()
298305

299306
$connection = Connection::fromDsn('redis://localhost/messenger-getnonblocking', ['delete_after_ack' => true], $redis);
300307

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+
}
306316
}
307317

308318
public function testGetAfterReject()
309319
{
310320
$redis = new \Redis();
311321
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', ['delete_after_ack' => true], $redis);
312322

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', []);
318326

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']);
321329

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+
}
323335
}
324336

325337
public function testItProperlyHandlesEmptyMessages()

0 commit comments

Comments
 (0)