Browse Source

Remove duplicate call to BufferHandler::close, fixes #386

Jordi Boggiano 11 years ago
parent
commit
16afa5ac26
2 changed files with 20 additions and 4 deletions
  1. 7 0
      src/Monolog/Handler/BufferHandler.php
  2. 13 4
      tests/Monolog/Handler/BufferHandlerTest.php

+ 7 - 0
src/Monolog/Handler/BufferHandler.php

@@ -91,6 +91,13 @@ class BufferHandler extends AbstractHandler
         $this->clear();
     }
 
+    public function __destruct()
+    {
+        // suppress the parent behavior since we already have register_shutdown_function()
+        // to call close(), and the reference contained there will prevent this from being
+        // GC'd until the end of the request
+    }
+
     /**
      * {@inheritdoc}
      */

+ 13 - 4
tests/Monolog/Handler/BufferHandlerTest.php

@@ -16,6 +16,8 @@ use Monolog\Logger;
 
 class BufferHandlerTest extends TestCase
 {
+    private $shutdownCheckHandler;
+
     /**
      * @covers Monolog\Handler\BufferHandler::__construct
      * @covers Monolog\Handler\BufferHandler::handle
@@ -38,15 +40,22 @@ class BufferHandlerTest extends TestCase
      * @covers Monolog\Handler\BufferHandler::close
      * @covers Monolog\Handler\BufferHandler::flush
      */
-    public function testDestructPropagatesRecords()
+    public function testPropagatesRecordsAtEndOfRequest()
     {
         $test = new TestHandler();
         $handler = new BufferHandler($test);
         $handler->handle($this->getRecord(Logger::WARNING));
         $handler->handle($this->getRecord(Logger::DEBUG));
-        $handler->__destruct();
-        $this->assertTrue($test->hasWarningRecords());
-        $this->assertTrue($test->hasDebugRecords());
+        $this->shutdownCheckHandler = $test;
+        register_shutdown_function(array($this, 'checkPropagation'));
+    }
+
+    public function checkPropagation()
+    {
+        if (!$this->shutdownCheckHandler->hasWarningRecords() || !$this->shutdownCheckHandler->hasDebugRecords()) {
+            echo '!!! BufferHandlerTest::testPropagatesRecordsAtEndOfRequest failed to verify that the messages have been propagated' . PHP_EOL;
+            exit(1);
+        }
     }
 
     /**