fix space between last date and number
authorChristian Weiske <cweiske@cweiske.de>
Sun, 4 Aug 2013 21:40:22 +0000 (23:40 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Sun, 4 Aug 2013 21:40:22 +0000 (23:40 +0200)
src/callnotifier/Logger/CallFileTop.php
tests/callnotifier/Logger/CallFileTopTest.php [new file with mode: 0644]

index 4fd8917b271593f533c3c752e312ae507b010e3b..1412782bd850b6aec130133ce0ad8f927be2cecb 100644 (file)
@@ -67,8 +67,13 @@ class Logger_CallFileTop extends Logger_CallBase
         if (isset($arLines[0]) && $arLines[0] == $date) {
             //same date as previous log entry
             $arLines = array_pad($arLines, -count($arLines) - 1, '');
+        } else if (!isset($arLines[0])) {
+            //empty file
+            $arLines = array_pad($arLines, -count($arLines) - 2, '');
         } else {
+            //new date
             $arLines = array_pad($arLines, -count($arLines) - 3, '');
+            $arLines[2] = "\n";
         }
         $arLines[0] = $date;
         $arLines[1] = $logline;
diff --git a/tests/callnotifier/Logger/CallFileTopTest.php b/tests/callnotifier/Logger/CallFileTopTest.php
new file mode 100644 (file)
index 0000000..4011f00
--- /dev/null
@@ -0,0 +1,60 @@
+<?php
+namespace callnotifier;
+
+class Logger_CallFileTopTest extends \PHPUnit_Framework_TestCase
+{
+    public function setUp()
+    {
+        static $registered = false;
+        if (!$registered) {
+            require_once 'Stream/Var.php';
+            stream_wrapper_register('var', '\\Stream_Var');
+            $registered = true;
+        }
+    }
+
+    public function testLogMultipleDates()
+    {
+        $file = 'var://GLOBALS/unittest';
+        $l = new Logger_CallFileTop($file, 'i', array('12345'));
+
+        $call = new CallMonitor_Call();
+        $call->type  = 'i';
+        $call->from  = '03411234567';
+        $call->to    = '12345';
+        $call->start = strtotime('2013-08-03 20:11');
+        $call->end   = strtotime('2013-08-03 20:12');
+        $l->log('finishedCall', array('call' => $call));
+
+        $call = new CallMonitor_Call();
+        $call->type  = 'i';
+        $call->from  = '03411234567';
+        $call->to    = '12345';
+        $call->start = strtotime('2013-08-03 21:13');
+        $call->end   = strtotime('2013-08-03 21:14');
+        $l->log('finishedCall', array('call' => $call));
+
+        $call = new CallMonitor_Call();
+        $call->type  = 'i';
+        $call->from  = '03411234567';
+        $call->to    = '12345';
+        $call->start = strtotime('2013-08-04 20:15');
+        $call->end   = strtotime('2013-08-04 20:16');
+        $l->log('finishedCall', array('call' => $call));
+
+        $this->assertEquals(
+<<<TXT
+04.08.2013, Sonntag
+  20:15  03411234567               00:01:00
+
+03.08.2013, Samstag
+  21:13  03411234567               00:01:00
+  20:11  03411234567               00:01:00
+
+TXT
+            ,
+            file_get_contents($file)
+        );
+    }
+}
+?>