فهرست منبع

FilterHandler: fix handle empty batch of filtered records

David Maicher 6 سال پیش
والد
کامیت
525d29847a
2فایلهای تغییر یافته به همراه9 افزوده شده و 1 حذف شده
  1. 1 1
      src/Monolog/Handler/FilterHandler.php
  2. 8 0
      tests/Monolog/Handler/FilterHandlerTest.php

+ 1 - 1
src/Monolog/Handler/FilterHandler.php

@@ -128,7 +128,7 @@ class FilterHandler extends AbstractHandler
             }
             }
         }
         }
 
 
-        $this->getHandler($filtered[count($filtered) - 1])->handleBatch($filtered);
+        $this->getHandler(count($filtered) > 0 ? $filtered[count($filtered) - 1] : null)->handleBatch($filtered);
     }
     }
 
 
     /**
     /**

+ 8 - 0
tests/Monolog/Handler/FilterHandlerTest.php

@@ -167,4 +167,12 @@ class FilterHandlerTest extends TestCase
         );
         );
         $handler->handle($this->getRecord(Logger::WARNING));
         $handler->handle($this->getRecord(Logger::WARNING));
     }
     }
+
+    public function testHandleEmptyBatch()
+    {
+        $test = new TestHandler();
+        $handler = new FilterHandler($test);
+        $handler->handleBatch(array());
+        $this->assertSame(array(), $test->getRecords());
+    }
 }
 }