[Messenger] Added check if json_encode succeeded
This commit is contained in:
parent
9e7a4102ad
commit
a16a574ca8
@ -186,6 +186,20 @@ class ConnectionTest extends TestCase
|
||||
$redis->del('messenger-getnonblocking');
|
||||
}
|
||||
|
||||
public function testJsonError()
|
||||
{
|
||||
$redis = new \Redis();
|
||||
|
||||
$connection = Connection::fromDsn('redis://localhost/json-error', [], $redis);
|
||||
|
||||
try {
|
||||
$connection->add("\xB1\x31", []);
|
||||
} catch (TransportException $e) {
|
||||
}
|
||||
|
||||
$this->assertSame('Malformed UTF-8 characters, possibly incorrectly encoded', $e->getMessage());
|
||||
}
|
||||
|
||||
public function testMaxEntries()
|
||||
{
|
||||
$redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock();
|
||||
|
@ -248,6 +248,10 @@ class Connection
|
||||
'uniqid' => uniqid('', true),
|
||||
]);
|
||||
|
||||
if (false === $message) {
|
||||
throw new TransportException(json_last_error_msg());
|
||||
}
|
||||
|
||||
$score = (int) ($this->getCurrentTimeInMilliseconds() + $delayInMs);
|
||||
$added = $this->connection->zadd($this->queue, ['NX'], $score, $message);
|
||||
} else {
|
||||
@ -256,6 +260,10 @@ class Connection
|
||||
'headers' => $headers,
|
||||
]);
|
||||
|
||||
if (false === $message) {
|
||||
throw new TransportException(json_last_error_msg());
|
||||
}
|
||||
|
||||
if ($this->maxEntries) {
|
||||
$added = $this->connection->xadd($this->stream, '*', ['message' => $message], $this->maxEntries, true);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user