Explorar o código

ZF-6395 & ZF-5950: Zend_Db_Profiler_Firebug throws exception when using filter

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19138 44c647ce-9c0f-0410-b52a-842ac1e357ba
mikaelkael %!s(int64=16) %!d(string=hai) anos
pai
achega
a4437e8c10

+ 14 - 3
library/Zend/Db/Profiler.php

@@ -68,6 +68,15 @@ class Zend_Db_Profiler
      */
     const TRANSACTION = 64;
 
+    /**
+     * Inform that a query is stored (in case of filtering)
+     */
+    const STORED = 'stored';
+
+    /**
+     * Inform that a query is ignored (in case of filtering)
+     */
+    const IGNORED = 'ignored';
 
     /**
      * Array of Zend_Db_Profiler_Query objects.
@@ -289,7 +298,7 @@ class Zend_Db_Profiler
     {
         // Don't do anything if the Zend_Db_Profiler is not enabled.
         if (!$this->_enabled) {
-            return;
+            return self::IGNORED;
         }
 
         // Check for a valid query handle.
@@ -321,7 +330,7 @@ class Zend_Db_Profiler
          */
         if (null !== $this->_filterElapsedSecs && $qp->getElapsedSecs() < $this->_filterElapsedSecs) {
             unset($this->_queryProfiles[$queryId]);
-            return;
+            return self::IGNORED;
         }
 
         /**
@@ -330,8 +339,10 @@ class Zend_Db_Profiler
          */
         if (null !== $this->_filterTypes && !($qp->getQueryType() & $this->_filterTypes)) {
             unset($this->_queryProfiles[$queryId]);
-            return;
+            return self::IGNORED;
         }
+
+        return self::STORED;
     }
 
     /**

+ 2 - 2
library/Zend/Db/Profiler/Firebug.php

@@ -121,9 +121,9 @@ class Zend_Db_Profiler_Firebug extends Zend_Db_Profiler
      */
     public function queryEnd($queryId)
     {
-        parent::queryEnd($queryId);
+        $state = parent::queryEnd($queryId);
 
-        if (!$this->getEnabled()) {
+        if (!$this->getEnabled() || $state == self::IGNORED) {
             return;
         }
 

+ 24 - 0
tests/Zend/Db/Profiler/FirebugTest.php

@@ -20,6 +20,11 @@
  * @version    $Id$
  */
 
+/**
+ * Test helper
+ */
+require_once dirname(dirname(dirname(dirname(__FILE__)))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
+
 /** PHPUnit_Framework_TestCase */
 require_once 'PHPUnit/Framework/TestCase.php';
 
@@ -180,6 +185,25 @@ class Zend_Db_Profiler_FirebugTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($messages);
     }
 
+    /**
+     * @group ZF-6395
+     */
+    public function testNoQueriesAfterFiltering()
+    {
+        $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();
+        $protocol = $channel->getProtocol(Zend_Wildfire_Plugin_FirePhp::PROTOCOL_URI);
+
+        $profiler = $this->_profiler->setEnabled(true);
+        $profiler->setFilterQueryType(Zend_Db_Profiler::INSERT | Zend_Db_Profiler::UPDATE);
+        $this->_db->fetchAll('select * from foo');
+
+        Zend_Wildfire_Channel_HttpHeaders::getInstance()->flush();
+
+        $messages = $protocol->getMessages();
+
+        $this->assertFalse($messages);
+    }
+
 }