From 5e24d85c8a8da5969db0f26717529bb60b4fa197 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 25 Oct 2014 17:45:00 +0200 Subject: [PATCH] Fix E_NOTICE emitted on empty response to INFO [section]. Empty responses can be returned when requesting an unsupported section with the INFO command. --- src/Command/ServerInfoV26x.php | 5 +++++ tests/Predis/Command/ServerInfoV26xTest.php | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/Command/ServerInfoV26x.php b/src/Command/ServerInfoV26x.php index 22165db2..c5034eaf 100644 --- a/src/Command/ServerInfoV26x.php +++ b/src/Command/ServerInfoV26x.php @@ -22,7 +22,12 @@ class ServerInfoV26x extends ServerInfo */ public function parseResponse($data) { + if ($data === '') { + return array(); + } + $info = array(); + $current = null; $infoLines = preg_split('/\r?\n/', $data); diff --git a/tests/Predis/Command/ServerInfoV26xTest.php b/tests/Predis/Command/ServerInfoV26xTest.php index a9a89b68..8ebffb06 100644 --- a/tests/Predis/Command/ServerInfoV26xTest.php +++ b/tests/Predis/Command/ServerInfoV26xTest.php @@ -291,6 +291,14 @@ BUFFER; $this->assertSame($expected, $this->getCommand()->parseResponse($raw)); } + /** + * @group disconnected + */ + public function testDoesNotEmitPhpNoticeOnEmptyResponse() + { + $this->assertSame(array(), $this->getCommand()->parseResponse('')); + } + /** * @group connected */