Jordi Boggiano 13 年之前
父節點
當前提交
04f41cd661
共有 2 個文件被更改,包括 12 次插入14 次删除
  1. 6 6
      src/Monolog/Handler/PushoverHandler.php
  2. 6 8
      tests/Monolog/Handler/PushoverHandlerTest.php

+ 6 - 6
src/Monolog/Handler/PushoverHandler.php

@@ -43,11 +43,12 @@ class PushoverHandler extends SocketHandler
 
     protected function generateDataStream($record)
     {
-        $content = $this->buildContentString($record);
-        return $this->buildHeaderAndAddContent($content);
+        $content = $this->buildContent($record);
+
+        return $this->buildHeader($content) . $content;
     }
 
-    private function buildContentString($record)
+    private function buildContent($record)
     {
         // Pushover has a limit of 512 characters on title and message combined.
         $maxMessageLength = 512 - strlen($this->title);
@@ -65,15 +66,14 @@ class PushoverHandler extends SocketHandler
         return http_build_query($dataArray);
     }
 
-    private function buildHeaderAndAddContent($content)
+    private function buildHeader($content)
     {
         $header = "POST /1/messages.json HTTP/1.1\r\n";
         $header .= "Host: api.pushover.net\r\n";
         $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
         $header .= "Content-Length: " . strlen($content) . "\r\n";
         $header .= "\r\n";
-        $header .= $content;
 
         return $header;
     }
-}
+}

+ 6 - 8
tests/Monolog/Handler/PushoverHandlerTest.php

@@ -79,15 +79,14 @@ class PushoverHandlerTest extends TestCase
         $this->assertRegexp('/message=' . $expectedMessage . '&title/', $content);
     }
 
-    private function createHandler($token = 'myToken', $user = 'myUser', $title = null)
+    private function createHandler($token = 'myToken', $user = 'myUser', $title = 'Monolog')
     {
-        $constructArray = array($token, $user);
-        if($title != null) {
-            $constructArray[2] = $title;
-        }
+        $constructorArgs = array($token, $user, $title);
         $this->res = fopen('php://memory', 'a');
         $this->handler = $this->getMock(
-            '\Monolog\Handler\PushoverHandler', array('fsockopen', 'streamSetTimeout'), $constructArray
+            '\Monolog\Handler\PushoverHandler',
+            array('fsockopen', 'streamSetTimeout'),
+            $constructorArgs
         );
 
         $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
@@ -103,5 +102,4 @@ class PushoverHandlerTest extends TestCase
 
         $this->handler->setFormatter($this->getIdentityFormatter());
     }
-
-}
+}