Quellcode durchsuchen

Fix E_NOTICE emitted on empty response to INFO [section].

Empty responses can be returned when requesting an unsupported section
with the INFO command.
Daniele Alessandri vor 10 Jahren
Ursprung
Commit
e2f4357ca3
2 geänderte Dateien mit 13 neuen und 0 gelöschten Zeilen
  1. 5 0
      src/Command/ServerInfoV26x.php
  2. 8 0
      tests/Predis/Command/ServerInfoV26xTest.php

+ 5 - 0
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);
 

+ 8 - 0
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
      */