Issues

ZF-11606: getRowCount() dies in Zend_Test_PHPUnit_Db_Connection

Issue Type: Bug Created: 2011-07-25T11:40:49.000+0000 Last Updated: 2011-07-25T11:58:39.000+0000 Status: Open Fix version(s): Reporter: Toshimasa Ishibashi (iandeth) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Test_PHPUnit

Related issues: Attachments:

Description

h1. ISSUE with an test class implementation like this,

<pre class="highlight">
class MyTest extends Zend_Test_PHPUnit_DatabaseTestCase {
  ...
  public function testFoo (){
    ...
    $this->getConnection()->getRowCount('guestbook');
    ...
  }
  ...
}

# run it,
$ phpunit MyTest.php

then you get: {quote} Fatal error: Call to a member function query() on a non-object in /path/to/lib/php/PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php on line 177 {quote}

h1. PROBLEM * getRowCount() is not overridden by Zend_Test_PHPUnit_Db_Connection class, the original (parent class) PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection's method is called. * in this PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection's getRowCount() implementation, it's using the property $this->connection * this is not used with Zend_Test_PHPUnit_Db_Connection, $this->_connection is the correct property to use. * thus, the non-object call.

h1. THE FIX * getRowCount() should be overrided by Zend_Test_PHPUnit_Db_Connection * below is the patch:

<pre class="highlight">
$ cd library/Zend/Test/PHPUnit/Db
$ diff -Naru Connection.php.original Connection.php 
--- Connection.php.original     2011-07-25 20:18:05.000000000 +0900
+++ Connection.php      2011-07-25 20:39:03.000000000 +0900
@@ -147,4 +147,14 @@
         return "DELETE";
     }
 
+    public function getRowCount($tableName, $whereClause = NULL)
+    {
+        $query = "SELECT COUNT(*) FROM ".$this->quoteSchemaObject($tableName);
+
+        if (isset($whereClause)) {
+            $query .= " WHERE {$whereClause}";
+        }
+
+        return (int) $this->_connection->query($query)->fetchColumn();
+    }
 }

h1. or... {quote} we can fiddle around *__get()* to pass $this->connection call to $this->_connection. {quote}

Comments

No comments to display

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts