Переглянути джерело

Promoted Zend_Test_PHPUnit_Db support to trunk

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16911 44c647ce-9c0f-0410-b52a-842ac1e357ba
matthew 16 роки тому
батько
коміт
78ed51d6c3
46 змінених файлів з 4564 додано та 0 видалено
  1. 1 0
      documentation/manual/en/manual.xml.in
  2. 69 0
      documentation/manual/en/module_specs/Zend_Test-PHPUnit-Db-Adapter.xml
  3. 309 0
      documentation/manual/en/module_specs/Zend_Test-PHPUnit-Db-Quickstart.xml
  4. 241 0
      documentation/manual/en/module_specs/Zend_Test-PHPUnit-Db-Testing.xml
  5. 41 0
      documentation/manual/en/module_specs/Zend_Test-PHPUnit-Db.xml
  6. 316 0
      library/Zend/Test/DbAdapter.php
  7. 381 0
      library/Zend/Test/DbStatement.php
  8. 151 0
      library/Zend/Test/PHPUnit/DatabaseTestCase.php
  9. 149 0
      library/Zend/Test/PHPUnit/Db/Connection.php
  10. 75 0
      library/Zend/Test/PHPUnit/Db/DataSet/DbRowset.php
  11. 123 0
      library/Zend/Test/PHPUnit/Db/DataSet/DbTable.php
  12. 103 0
      library/Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php
  13. 86 0
      library/Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php
  14. 68 0
      library/Zend/Test/PHPUnit/Db/DataSet/QueryTable.php
  15. 41 0
      library/Zend/Test/PHPUnit/Db/Exception.php
  16. 164 0
      library/Zend/Test/PHPUnit/Db/Metadata/Generic.php
  17. 69 0
      library/Zend/Test/PHPUnit/Db/Operation/DeleteAll.php
  18. 92 0
      library/Zend/Test/PHPUnit/Db/Operation/Insert.php
  19. 98 0
      library/Zend/Test/PHPUnit/Db/Operation/Truncate.php
  20. 95 0
      library/Zend/Test/PHPUnit/Db/SimpleTester.php
  21. 4 0
      tests/Zend/Test/AllTests.php
  22. 111 0
      tests/Zend/Test/DbAdapterTest.php
  23. 165 0
      tests/Zend/Test/DbStatementTest.php
  24. 2 0
      tests/Zend/Test/PHPUnit/AllTests.php
  25. 57 0
      tests/Zend/Test/PHPUnit/Db/AllTests.php
  26. 91 0
      tests/Zend/Test/PHPUnit/Db/ConnectionTest.php
  27. 51 0
      tests/Zend/Test/PHPUnit/Db/DataSet/AllTests.php
  28. 55 0
      tests/Zend/Test/PHPUnit/Db/DataSet/DataSetTestCase.php
  29. 98 0
      tests/Zend/Test/PHPUnit/Db/DataSet/DbRowsetTest.php
  30. 72 0
      tests/Zend/Test/PHPUnit/Db/DataSet/DbTableDataSetTest.php
  31. 87 0
      tests/Zend/Test/PHPUnit/Db/DataSet/DbTableTest.php
  32. 83 0
      tests/Zend/Test/PHPUnit/Db/DataSet/QueryDataSetTest.php
  33. 110 0
      tests/Zend/Test/PHPUnit/Db/DataSet/QueryTableTest.php
  34. 141 0
      tests/Zend/Test/PHPUnit/Db/Integration/AbstractTestCase.php
  35. 70 0
      tests/Zend/Test/PHPUnit/Db/Integration/MysqlIntegrationTest.php
  36. 54 0
      tests/Zend/Test/PHPUnit/Db/Integration/SqLiteIntegrationTest.php
  37. 6 0
      tests/Zend/Test/PHPUnit/Db/Integration/_files/sqliteIntegrationFixture.xml
  38. 112 0
      tests/Zend/Test/PHPUnit/Db/Metadata/GenericTest.php
  39. 45 0
      tests/Zend/Test/PHPUnit/Db/Operation/AllTests.php
  40. 89 0
      tests/Zend/Test/PHPUnit/Db/Operation/DeleteAllTest.php
  41. 89 0
      tests/Zend/Test/PHPUnit/Db/Operation/InsertTest.php
  42. 93 0
      tests/Zend/Test/PHPUnit/Db/Operation/TruncateTest.php
  43. 6 0
      tests/Zend/Test/PHPUnit/Db/Operation/_files/insertFixture.xml
  44. 5 0
      tests/Zend/Test/PHPUnit/Db/Operation/_files/truncateFixture.xml
  45. 77 0
      tests/Zend/Test/PHPUnit/Db/SimpleTesterTest.php
  46. 119 0
      tests/Zend/Test/PHPUnit/Db/TestCaseTest.php

+ 1 - 0
documentation/manual/en/manual.xml.in

@@ -502,6 +502,7 @@
         <title>Zend_Test</title>
         <xi:include href="module_specs/Zend_Test.xml" />
         <xi:include href="module_specs/Zend_Test-PHPUnit.xml" parse="xml" />
+        <xi:include href="module_specs/Zend_Test-PHPUnit-Db.xml" parse="xml" />
     </chapter>
 
     <chapter id="zend.text">

+ 69 - 0
documentation/manual/en/module_specs/Zend_Test-PHPUnit-Db-Adapter.xml

@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect2 id="zend.test.phpunit.db.adapter">
+    <title>Using the Database Testing Adapter</title>
+
+    <para>
+        There are times when you don't want to test parts of your application with a real database, 
+        but are forced to because of coupling. The <classname>Zend_Test_DbAdapter</classname> offers
+        a convenient way to use a implementation of <classname>Zend_Db_Adapter_Abstract</classname> 
+        without having to open a database connection. Furthermore this Adapter is very easy to mock 
+        from within your PHPUnit testsuite, since it requires no constructor arguments.
+    </para>
+
+    <para>
+        The Test Adapter acts as a stack for various database results. Its order of results have to
+        be userland implemented, which might be a tedious task for tests that call many different 
+        database queries, but its just the right helper for tests where only a handful of queries 
+        are executed and you know the exact order of the results that have to be returned to your 
+        userland code.
+    </para>
+
+    <programlisting language="php"><![CDATA[
+$adapter   = new Zend_Test_DbAdapter();
+$stmt1Rows = array(array('foo' => 'bar'), array('foo' => 'baz'));
+$stmt1     = Zend_Test_DbStatement::createSelectStatement($stmt1Rows);
+$adapter->appendStatementToStack($stmt1);
+
+$stmt2Rows = array(array('foo' => 'bar'), array('foo' => 'baz'));
+$stmt2     = Zend_Test_DbStatement::createSelectStatement($stmt2Rows);
+$adapter->appendStatementToStack($stmt2);
+
+$rs = $adapter->query('SELECT ...'); // Returns Statement 2
+while ($row = $rs->fetch()) {
+    echo $rs['foo']; // Prints "Bar", "Baz"
+}
+$rs = $adapter->query('SELECT ...'); // Returns Statement 1
+]]></programlisting>
+
+    <para>
+        Behaviour of any real database adapter is simulated as much as possible such that methods 
+        like <methodname>fetchAll()</methodname>, <methodname>fetchObject()</methodname>, 
+        <methodname>fetchColumn</methodname> and more are working for the test adapter.
+    </para>
+
+    <para>
+        You can also put INSERT, UPDATE and DELETE statement onto the result stack, these however 
+        only return a statement which allows to specifiy the result of 
+        <methodname>$stmt->rowCount()</methodname>.
+    </para>
+
+    <programlisting role="php"><![CDATA[
+$adapter = new Zend_Test_DbAdapter();
+$adapter->appendStatementToStack(Zend_Test_DbStatement::createInsertStatement(1));
+$adapter->appendStatementToStack(Zend_Test_DbStatement::createUpdateStatement(2));
+$adapter->appendStatementToStack(Zend_Test_DbStatement::createDeleteStatement(10));
+]]></programlisting>
+
+    <para>
+        The test adapter never checks if the query specified is really of the type SELECT, DELETE, 
+        INSERT or UPDATE which is returned next from the stack. The correct order of returning the 
+        data has to be implemented by the user of the test adapter.
+    </para>
+
+    <para>
+        The Test adapter also specifies methods to simulate the use of the methods 
+        <methodname>listTables()</methodname>, <methodname>describeTables()</methodname> and 
+        <methodname>lastInsertId()</methodname>.
+    </para>
+</sect2>

+ 309 - 0
documentation/manual/en/module_specs/Zend_Test-PHPUnit-Db-Quickstart.xml

@@ -0,0 +1,309 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect2 id="zend.test.phpunit.db.quickstart">
+    <title>Quickstart</title>
+
+    <sect3 id="zend.test.phpunit.db.quickstart.testcase">
+        <title>Setup a Database TestCase</title>
+        
+        <para>
+            We are now writting some database tests for the Bug Database example in the 
+            <classname>Zend_Db_Table</classname> documentation. First we begin to test that 
+            inserting a new bug is actually saved in the database correctly. First we have to 
+            setup a test-class that extends 
+            <classname>Zend_Test_PHPUnit_DatabaseTestCase</classname>. This class extends the
+            PHPUnit Database Extension, which in turn extends the basic 
+            <classname>PHPUnit_Framework_TestCase</classname>. A database testcase contains two
+            abstract methods that have to be implemented, one for the database connection and 
+            one for the initial dataset that should be used as seed or fixture.
+        </para>
+
+        <note>
+            <para>
+                You should be familiar with the PHPUnit Database extension to follow this quickstart
+                easily. Although all the concepts are explained in this documentation it may be 
+                helpful to read the PHPUnit documentation first.
+            </para>
+        </note>
+
+        <programlisting language="php"><![CDATA[
+class BugsTest extends Zend_Test_PHPUnit_DatabaseTestCase
+{
+    private $_connectionMock;
+    
+    /**
+     * Returns the test database connection.
+     *
+     * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
+     */
+    protected function getConnection()
+    {
+        if($this->_connectionMock == null) {
+            $connection = Zend_Db::factory(...);
+            $this->_connectionMock = $this->createZendDbConnection(
+                $connection, 'zfunittests'
+            );
+            Zend_Db_Table_Abstract::setDefaultAdapter($connection);
+        }
+        return $this->_connectionMock;
+    }
+    
+    /**
+     * @return PHPUnit_Extensions_Database_DataSet_IDataSet
+     */
+    protected function getDataSet()
+    {
+        return $this->createFlatXmlDataSet(
+            dirname(__FILE__) . '/_files/bugsSeed.xml'
+        );
+    }
+}
+]]></programlisting>
+
+        <para>
+            Here we create the database connection and seed some data into the database. Some 
+            important details should be noted on this code:
+        </para>
+
+        <itemizedlist>
+            <listitem>
+                <para>
+                    You cannot directly return a <classname>Zend_Db_Adapter_Abstract</classname>
+                    from the <methodname>getConnection()</methodname> method, but a PHPUnit 
+                    specific wrapper which is generated with the 
+                    <methodname>createZendDbConnection()</methodname> method.
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    The database schema (tables and database) is not re-created on every 
+                    testrun. The database and tables have to be created manually before running 
+                    the tests.
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    Database tests by default truncate the data during 
+                    <methodname>setUp()</methodname> and then insert the seed data which is 
+                    returned from the <methodname>getDataSet()</methodname> method.
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    DataSets have to implement the interface 
+                    <classname>PHPUnit_Extensions_Database_DataSet_IDataSet</classname>.  
+                    There is a wide range of XML and YAML configuration file types included in 
+                    PHPUnit which allows to specifiy how the tables and datasets should look 
+                    like and you should look into the PHPUnit documentation to get the latest 
+                    information on these dataset specifications.
+                </para>
+            </listitem>
+        </itemizedlist>
+    </sect3>
+
+    <sect3 id="zend.test.phpunit.db.quickstart.dataset">
+        <title>Specify a seed dataset</title>
+
+        <para>
+            In the previous setup for the database testcase we have specified a seed file for the
+            database fixture.  We now create this file specified in the Flat XML format:
+        </para>
+
+        <programlisting language="xml"><![CDATA[
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+    <zfbugs bug_id="1" bug_description="system needs electricity to run" 
+        bug_status="NEW" created_on="2007-04-01 00:00:00" 
+        updated_on="2007-04-01 00:00:00" reported_by="goofy" 
+        assigned_to="mmouse" verified_by="dduck" />
+    <zfbugs bug_id="2" bug_description="Implement Do What I Mean function" 
+        bug_status="VERIFIED" created_on="2007-04-02 00:00:00" 
+        updated_on="2007-04-02 00:00:00" reported_by="goofy" 
+        assigned_to="mmouse" verified_by="dduck" />
+    <zfbugs bug_id="3" bug_description="Where are my keys?" bug_status="FIXED"
+        created_on="2007-04-03 00:00:00" updated_on="2007-04-03 00:00:00"
+        reported_by="dduck" assigned_to="mmouse" verified_by="dduck" />
+    <zfbugs bug_id="4" bug_description="Bug no product" bug_status="INCOMPLETE"
+        created_on="2007-04-04 00:00:00" updated_on="2007-04-04 00:00:00"
+        reported_by="mmouse" assigned_to="goofy" verified_by="dduck" />
+</dataset>
+]]></programlisting>
+
+        <para>
+            We will work with this four entries in the database table "zfbugs" in the next 
+            examples. The required MySQL schema for this example is:
+        </para>
+
+        <programlisting language="sql"><![CDATA[
+CREATE TABLE IF NOT EXISTS `zfbugs` (
+    `bug_id` int(11) NOT NULL auto_increment,
+    `bug_description` varchar(100) default NULL,
+    `bug_status` varchar(20) default NULL,
+    `created_on` datetime default NULL,
+    `updated_on` datetime default NULL,
+    `reported_by` varchar(100) default NULL,
+    `assigned_to` varchar(100) default NULL,
+    `verified_by` varchar(100) default NULL,
+PRIMARY KEY  (`bug_id`)
+) ENGINE=InnoDB AUTO_INCREMENT=1 ;
+]]></programlisting>
+    </sect3>
+
+    <sect3 id="zend.test.phpunit.db.quickstart.initial-tests">
+        <title>A few initial database tests</title>
+
+        <para>
+            Now that we have implemented the two required abstract methods of the 
+            <classname>Zend_Test_PHPUnit_DatabaseTestCase</classname> and specified the seed 
+            database content, which will be re-created for each new test, we can go about to make
+            our first assertion. This will be a test to insert a new bug.
+        </para>
+
+        <programlisting language="php"><![CDATA[
+class BugsTest extends Zend_Test_PHPUnit_DatabaseTestCase
+{
+    public function testBugInsertedIntoDatabase()
+    {
+        $bugsTable = new Bugs();
+    
+        $data = array(
+            'created_on'      => '2007-03-22 00:00:00',
+            'updated_on'      => '2007-03-22 00:00:00',
+            'bug_description' => 'Something wrong',
+            'bug_status'      => 'NEW',
+            'reported_by'     => 'garfield',
+            'verified_by'     => 'garfield',
+            'assigned_to'     => 'mmouse',
+        );
+    
+        $bugsTable->insert($data);
+    
+        $ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet($this->getConnection());
+        $ds->addTable('zfbugs', 'SELECT * FROM zfbugs');
+    
+        $this->assertDataSetsEqual(
+            $this->createFlatXmlDataSet(dirname(__FILE__)."/_files/bugsInsertIntoAssertion.xml"),
+            $ds
+        );
+    }
+}
+]]></programlisting>
+
+        <para>
+            Now up to the <methodname>$bugsTable->insert($data);</methodname> everything looks
+            familiar.  The lines after that contain the assertion methodname. We want to verify
+            that after inserting the new bug the database has been updated correctly with the 
+            given data.  For this we create a 
+            <classname>Zend_Test_PHPUnit_Db_DataSet_QueryDataSet</classname> instance and give 
+            it a database connection. We will then tell this dataset that it contains a table 
+            "zfbugs" which is given by an SQL statement. This current/actual state of the 
+            database is compared to the expected database state which is contained in another 
+            XML file "bugsInsertIntoAssertions.xml". This XML file is a slight deviation from 
+            the one given above and contains another row with the expected data:
+        </para>
+
+        <programlisting language="xml"><![CDATA[
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+    <!-- previous 4 rows -->
+    <zfbugs bug_id="5" bug_description="Something wrong" bug_status="NEW"
+        created_on="2007-03-22 00:00:00" updated_on="2007-03-22 00:00:00"
+        reported_by="garfield" assigned_to="mmouse" verified_by="garfield" />
+</dataset>
+]]></programlisting>
+
+        <para>
+            There are other ways to assert that the current database state equals an expected 
+            state.  The "Bugs" table in the example already nows a lot about its inner state, so
+            why not use this to our advantage? The next example will assert that deleting from 
+            the database is possible:
+        </para>
+
+        <programlisting language="php"><![CDATA[
+class BugsTest extends Zend_Test_PHPUnit_DatabaseTestCase
+{
+    public function testBugDelete()
+    {
+        $bugsTable = new Bugs();
+    
+        $bugsTable->delete(
+            $bugsTable->getAdapter()->quoteInto("bug_id = ?", 4)
+        );
+    
+        $ds = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
+        $ds->addTable($bugsTable);
+    
+        $this->assertDataSetsEqual(
+            $this->createFlatXmlDataSet(dirname(__FILE__)."/_files/bugsDeleteAssertion.xml"),
+            $ds
+        );
+    }
+}
+]]></programlisting>
+
+        <para>
+            We have created a <classname>Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet</classname>
+            dataset here, which takes any <classname>Zend_Db_Table_Abstract</classname> instance
+            and adds it to the dataset with its table name, in this example "zfbugs". You could 
+            add several tables more if you wanted using the method 
+            <methodname>addTable()</methodname> if you want to check for expected database state
+            in more than one table.
+        </para>
+
+        <para>
+            Here we only have one table and check against an expected database state in 
+            "bugsDeleteAssertion.xml" which is the original seed dataset without the row with id
+            4.
+        </para>
+
+        <para>
+            Since we have only checked that two specific tables (not datasets) are equal in the
+            previous examples we should also look at how to assert that two tables are equal. 
+            Therefore we will add another test to our TestCase which verifies updating behaviour
+            of a dataset.
+        </para>
+
+        <programlisting lanugage="php"><![CDATA[
+class BugsTest extends Zend_Test_PHPUnit_DatabaseTestCase
+{
+    public function testBugUpdate()
+    {
+        $bugsTable = new Bugs();
+    
+        $data = array(
+            'updated_on'      => '2007-05-23',
+            'bug_status'      => 'FIXED'
+        );
+    
+        $where = $bugsTable->getAdapter()->quoteInto('bug_id = ?', 1);
+    
+        $bugsTable->update($data, $where);
+    
+        $rowset = $bugsTable->fetchAll();
+    
+        $ds        = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset);
+        $assertion = $this->createFlatXmlDataSet(
+            dirname(__FILE__) . '/_files/bugsUpdateAssertion.xml'
+        );
+        $expectedRowsets = $assertion->getTable('zfbugs');
+    
+        $this->assertTablesEqual(
+            $expectedRowsets, $ds
+        );
+    }
+}
+]]></programlisting>
+
+        <para>
+            Here we create the current database state from a 
+            <classname>Zend_Db_Table_Rowset_Abstract</classname> instance in conjunction with 
+            the <classname>Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset)</classname> instance
+            which creates an internal data-representation of the rowset.  This can again be 
+            compared against another data-table by using the 
+            <methodname>$this->assertTablesEqual()</methodname> assertion.
+        </para>
+    </sect3>
+</sect2>

+ 241 - 0
documentation/manual/en/module_specs/Zend_Test-PHPUnit-Db-Testing.xml

@@ -0,0 +1,241 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect2 id="zend.test.phpunit.db.testing">
+    <title>Usage, API and Extensions Points</title>
+
+    <para>
+        The Quickstart already gave a good introduction on how database testing can be done using 
+        PHPUnit and the Zend Framework. This section gives an overview over the API that the 
+        <classname>Zend_Test_PHPUnit_Db</classname> component comes with and how it works 
+        internally.
+    </para>
+
+    <note>
+        <title>Some Remarks on Database Testing</title>
+
+        <para>
+            Just as the Controller TestCase is testing an application at an integration level, the 
+            Database TestCase is an integration testing method. Its using several different 
+            application layers for testing purposes and therefore should be consumed with caution.
+        </para>
+
+        <para>
+            It should be noted that testing domain and business logic with integration tests such
+            as Zend Framework's Controller and Database TestCases is a bad practice. The purpose of 
+            an Integration test is to check that several parts of an application work smoothly when
+            wired together. These integration tests do not replace the need for a set of unit tests
+            that test the domain and business logic at a much smaller level, the isolated class.
+        </para>
+    </note>
+
+    <sect3 id="zend.test.phpunit.db.testing.testcase">
+        <title>The Zend_Test_PHPUnit_DatabaseTestCase class</title>
+
+        <para>
+            The <classname>Zend_Test_PHPUnit_DatabaseTestCase</classname> class derives from the 
+            <classname>PHPUnit_Extensions_Database_TestCase</classname> which allows to setup tests 
+            with a fresh database fixture on each run easily. The Zend implementation offers some 
+            additional convenience features over the PHPUnit Database extension when it comes to 
+            using <classname>Zend_Db</classname> resources inside your tests. The workflow of a 
+            database test-case can be described as follows.
+        </para>
+
+        <orderedlist>
+            <listitem>
+                <para>
+                    For each test PHPUnit creates a new instance of the TestCase and calls the 
+                    <methodname>setUp()</methodname> method.
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    The Database TestCase creates an instance of a Database Tester which handles the
+                    setting up and tearing down of the database.
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    The database tester collects the information on the database connection and 
+                    initial dataset from <methodname>getConnection()</methodname> and 
+                    <methodname>getDataSet()</methodname> which are both abstract methods and have 
+                    to be implemented by any Database Testcase.
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    By default the database tester truncates the tables specified in the given 
+                    dataset, and then inserts the data given as initial fixture.
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    When the database tester has finished setting up the database, PHPUnit runs the 
+                    test.
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    After running the test, <methodname>tearDown()</methodname> is called. Because 
+                    the database is wiped in <methodname>setUp()</methodname> before inserting the 
+                    required initial fixture, no actions are executed by the database tester at this
+                    stage.
+                </para>
+            </listitem>
+        </orderedlist>
+
+        <note>
+            <para>
+                The Database TestCase expects the database schema and tables to be setup correctly
+                to run the tests. There is no mechanism to create and tear down database tables.
+            </para>
+        </note>
+
+        <para>
+            The <classname>Zend_Test_PHPUnit_DatabaseTestCase</classname> class has some convenience
+            functions that can help writing tests that interact with the database and the database 
+            testing extension.
+        </para>
+
+        <table id="zend.test.phpunit.db.testing.testcase.api-methods">
+            <title>Zend_Test_PHPUnit_DatabaseTestCase API Methods</title>
+
+            <para>
+                This lists only the new methods compared to the 
+                <classname>PHPUnit_Extensions_Database_TestCase</classname>, whose <ulink 
+                    url="http://www.phpunit.de/manual/current/en/database.html">API is documented in
+                the PHPUnit Documentation</ulink>.
+            </para>
+
+            <tgroup cols="2">
+                <thead>
+                    <row>
+                        <entry>Method</entry>
+                        <entry>Description</entry>
+                    </row>
+                </thead>
+
+                <tbody>
+                    <row>
+                        <entry>
+                            <methodname>createZendDbConnection(Zend_Db_Adapter_Abstract $connection,
+                                $schema)</methodname>
+                        </entry>
+                        
+                        <entry>
+                            Create a PHPUnit Database Extension compatible Connection instance from 
+                            a <classname>Zend_Db_Adapter_Abstract</classname> instance.  This method
+                            should be used in for testcase setup when implementing the abstract 
+                            <methodname>getConnection()</methodname> method of the database testcase.
+                        </entry>
+                    </row>
+
+                    <row>
+                        <entry><methodname>getAdapter()</methodname></entry>
+
+                        <entry>
+                            Convenience method to access the underlying 
+                            <classname>Zend_Db_Adapter_Abstract</classname> instance which is nested
+                            inside the PHPUnit database connection created with
+                            <methodname>getConnection()</methodname>.
+                        </entry>
+                    </row>
+
+                    <row>
+                        <entry>
+                            <methodname>createDbRowset(Zend_Db_Table_Rowset_Abstract $rowset, 
+                                $tableName = null)</methodname>
+                        </entry>
+
+                        <entry>
+                            Create a DataTable Object that is filled with the data from a given 
+                            <classname>Zend_Db_Table_Rowset_Abstract</classname> instance. The table
+                            the rowset is connected to is chosen when <code>$tableName</code> is 
+                            null.
+                        </entry>
+                    </row>
+
+                    <row>
+                        <entry>
+                            <methodname>createDbTable(Zend_Db_Table_Abstract $table, $where = null, 
+                                $order = null, $count = null, $offset = null)</methodname>
+                        </entry>
+
+                        <entry>
+                            Create a DataTable object that represents the data contained in a 
+                            <classname>Zend_Db_Table_Abstract</classname> instance. For retrieving 
+                            the data <methodname>fetchAll()</methodname> is used, where the optional
+                            parameters can be used to restrict the data table to a certain subset.
+                        </entry>
+                    </row>
+
+                    <row>
+                        <entry>
+                            <methodname>createDbTableDataSet(array $tables=array())</methodname>
+                        </entry>
+
+                        <entry>
+                            Create a DataSet containing the given <code>$tables</code>, an array of
+                            <classname>Zend_Db_Table_Abstract</classname> instances.
+                        </entry>
+                    </row>
+                </tbody>
+            </tgroup>
+        </table>
+    </sect3>
+
+    <sect3 id="zend.test.phpunit.db.testing.controllerintegration">
+        <title>Integrating Database Testing with the ControllerTestCase</title>
+
+        <para>
+            Because PHP does not support multiple inheritance it is not possible to use the 
+            Controller and Database testcases in conjunction. However you can use the 
+            <classname>Zend_Test_PHPUnit_Db_SimpleTester</classname> database tester in your 
+            controller test-case to setup a database enviroment fixture for each new controller 
+            test. The Database TestCase in general is only a set of convenience functions which can
+            also be accessed and used without the test case.
+        </para>
+
+        <example id="zend.test.phpunit.db.testing.controllerintegration.example">
+            <para>
+                This example extends the User Controller Test from the 
+                <classname>Zend_Test_PHPUnit_ControllerTestCase</classname> documentation to include
+                a database setup.
+            </para>
+
+            <programlisting language="php"><![CDATA[
+class UserControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
+{
+    public function setUp()
+    {
+        $this->setupDatabase();
+        $this->bootstrap = array($this, 'appBootstrap');
+        parent::setUp();
+    }
+
+    public function setupDatabase()
+    {
+        $db = Zend_Db::factory(...);
+        $connection = Zend_Test_PHPUnit_Db_Connection($db, 'database_schema_name');
+        $databaseTester = new Zend_Test_PHPUnit_Db_SimpleTester($connection);
+
+        $databaseFixture = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(
+            dirname(__FILE__) . '/_files/initialUserFixture.xml'
+        );
+
+        $databaseTester->setupDatabase($databaseFixture);
+    }
+}
+]]></programlisting>
+
+            <para>
+                Now the Flat XML dataset "initialUserFixture.xml" is used to set the database into 
+                an initial state before each test, exactly as the DatabaseTestCase works internally.
+            </para>
+        </example>
+    </sect3>
+</sect2>

+ 41 - 0
documentation/manual/en/module_specs/Zend_Test-PHPUnit-Db.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect1 id="zend.test.phpunit.db"  xmlns:xi="http://www.w3.org/2001/XInclude">
+    <title>Zend_Test_PHPUnit_Db</title>
+
+    <para>
+        Coupling of data-access and the domain model often requires the use of a database for 
+        testing purposes. But the database is persistet accross different tests which leads to 
+        test results that can affect each other. Furthermore setting up the database to be able to 
+        run a test is quite some work. PHPUnit's Database extension simplifies testing with a 
+        database by offering a very simple mechanism to setup and teardown the database between 
+        different tests. This component extends the PHPUnit Database extension with Zend Framework
+        specific code, such that writing database tests against a Zend Framework application is 
+        simplified.
+    </para>
+
+    <para>
+        Database Testing can be explained with two conceptual entities, DataSets and DataTables.
+        Internally the PHPUnit Database extension can build up an object structure of a database, 
+        its tables and containing rows from configuration files or the real database content. This
+        abstract object graph can then be compared using assertions. A common use-case in database 
+        testing is setting up some tables with seed data, then performing some operations, and 
+        finally asserting that the operated on database-state is equal to some predefined expected 
+        state.  <classname>Zend_Test_PHPUnit_Db</classname> simplifies this task by allowing to 
+        generate DataSets and DataTables from existing <classname>Zend_Db_Table_Abstract</classname>
+        or <classname>Zend_Db_Table_Rowset_Abstract</classname> instances.
+    </para>
+
+    <para>
+        Furthermore this component allows to integrate any 
+        <classname>Zend_Db_Adapter_Abstract</classname> for testing wheras the original extension
+        only works with <classname>PDO</classname>. A Test Adapter implementation for
+        <classname>Zend_Db_Adapter_Abstract</classname> is also included in this component.  It
+        allows to instantiate a Db Adapter that requires no database at all and acts as an SQL and
+        result stack which is used by the API methods.
+    </para>
+
+    <xi:include href="Zend_Test-PHPUnit-Db-Quickstart.xml" />
+    <xi:include href="Zend_Test-PHPUnit-Db-Testing.xml" />
+    <xi:include href="Zend_Test-PHPUnit-Db-Adapter.xml" />
+</sect1>

+ 316 - 0
library/Zend/Test/DbAdapter.php

@@ -0,0 +1,316 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Db_Adapter_Abstract
+ */
+require_once "Zend/Db/Adapter/Abstract.php";
+
+/**
+ * @see Zend_Test_DbStatement
+ */
+require_once "Zend/Test/DbStatement.php";
+
+/**
+ * Testing Database Adapter which acts as a stack for SQL Results
+ *
+ * @uses       uses
+ * @category   Zend
+ * @package    package
+ * @subpackage subpackage
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_DbAdapter extends Zend_Db_Adapter_Abstract
+{
+    /**
+     * @var array
+     */
+    protected $_statementStack = array();
+
+    /**
+     * @var boolean
+     */
+    protected $_connected = false;
+
+    /**
+     * @var array
+     */
+    protected $_listTables = array();
+
+    /**
+     * @var array
+     */
+    protected $_lastInsertIdStack = array();
+
+    /**
+     * @var array
+     */
+    protected $_describeTables = array();
+
+    /**
+     * Empty constructor to make it parameterless.
+     */
+    public function __construct()
+    {        
+    }
+
+    /**
+     * Append a new Statement to the SQL Result Stack.
+     *
+     * @param  Zend_Test_DbStatement $stmt
+     * @return Zend_Test_DbAdapter
+     */
+    public function appendStatementToStack(Zend_Test_DbStatement $stmt)
+    {
+        array_push($this->_statementStack, $stmt);
+        return $this;
+    }
+
+    /**
+     * Append a new Insert Id to the {@see lastInsertId}.
+     * 
+     * @param  int|string $id
+     * @return Zend_Test_DbAdapter
+     */
+    public function appendLastInsertIdToStack($id)
+    {
+        array_push($this->_lastInsertIdStack, $id);
+        return $this;
+    }
+
+    /**
+     * Returns the symbol the adapter uses for delimited identifiers.
+     *
+     * @return string
+     */
+    public function getQuoteIdentifierSymbol()
+    {
+        return '';
+    }
+
+    /**
+     * Set the result from {@see listTables()}.
+     *
+     * @param array $listTables
+     */
+    public function setListTables(array $listTables)
+    {
+        $this->_listTables = $listTables;
+    }
+
+    /**
+     * Returns a list of the tables in the database.
+     *
+     * @return array
+     */
+    public function listTables()
+    {
+       return $this->_listTables;
+    }
+
+    /**
+     *
+     * @param  string $table
+     * @param  array $tableInfo
+     * @return Zend_Test_DbAdapter
+     */
+    public function setDescribeTable($table, $tableInfo)
+    {
+        $this->_describeTables[$table] = $tableInfo;
+        return $this;
+    }
+
+    /**
+     * Returns the column descriptions for a table.
+     *
+     * The return value is an associative array keyed by the column name,
+     * as returned by the RDBMS.
+     *
+     * The value of each array element is an associative array
+     * with the following keys:
+     *
+     * SCHEMA_NAME => string; name of database or schema
+     * TABLE_NAME  => string;
+     * COLUMN_NAME => string; column name
+     * COLUMN_POSITION => number; ordinal position of column in table
+     * DATA_TYPE   => string; SQL datatype name of column
+     * DEFAULT     => string; default expression of column, null if none
+     * NULLABLE    => boolean; true if column can have nulls
+     * LENGTH      => number; length of CHAR/VARCHAR
+     * SCALE       => number; scale of NUMERIC/DECIMAL
+     * PRECISION   => number; precision of NUMERIC/DECIMAL
+     * UNSIGNED    => boolean; unsigned property of an integer type
+     * PRIMARY     => boolean; true if column is part of the primary key
+     * PRIMARY_POSITION => integer; position of column in primary key
+     *
+     * @param string $tableName
+     * @param string $schemaName OPTIONAL
+     * @return array
+     */
+    public function describeTable($tableName, $schemaName = null)
+    {
+        if(isset($this->_describeTables[$tableName])) {
+            return $this->_describeTables[$tableName];
+        } else {
+            return array();
+        }
+    }
+
+    /**
+     * Creates a connection to the database.
+     *
+     * @return void
+     */
+    protected function _connect()
+    {
+        $this->_connected = true;
+    }
+
+    /**
+     * Test if a connection is active
+     *
+     * @return boolean
+     */
+    public function isConnected()
+    {
+        return $this->_connected;
+    }
+
+    /**
+     * Force the connection to close.
+     *
+     * @return void
+     */
+    public function closeConnection()
+    {
+        $this->_connected = false;
+    }
+
+    /**
+     * Prepare a statement and return a PDOStatement-like object.
+     *
+     * @param string|Zend_Db_Select $sql SQL query
+     * @return Zend_Db_Statment|PDOStatement
+     */
+    public function prepare($sql)
+    {
+        if(count($this->_statementStack)) {
+            return array_pop($this->_statementStack);
+        } else {
+            return new Zend_Test_DbStatement();
+        }
+    }
+
+    /**
+     * Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column.
+     *
+     * As a convention, on RDBMS brands that support sequences
+     * (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence
+     * from the arguments and returns the last id generated by that sequence.
+     * On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method
+     * returns the last value generated for such a column, and the table name
+     * argument is disregarded.
+     *
+     * @param string $tableName   OPTIONAL Name of table.
+     * @param string $primaryKey  OPTIONAL Name of primary key column.
+     * @return string
+     */
+    public function lastInsertId($tableName = null, $primaryKey = null)
+    {
+        if(count($this->_lastInsertIdStack)) {
+            return array_pop($this->_lastInsertIdStack);
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Begin a transaction.
+     */
+    protected function _beginTransaction()
+    {
+        return;
+    }
+
+    /**
+     * Commit a transaction.
+     */
+    protected function _commit()
+    {
+        
+    }
+
+    /**
+     * Roll-back a transaction.
+     */
+    protected function _rollBack()
+    {
+
+    }
+
+    /**
+     * Set the fetch mode.
+     *
+     * @param integer $mode
+     * @return void
+     * @throws Zend_Db_Adapter_Exception
+     */
+    public function setFetchMode($mode)
+    {
+        return;
+    }
+
+    /**
+     * Adds an adapter-specific LIMIT clause to the SELECT statement.
+     *
+     * @param mixed $sql
+     * @param integer $count
+     * @param integer $offset
+     * @return string
+     */
+    public function limit($sql, $count, $offset = 0)
+    {
+        return sprintf('%s LIMIT %d,%d', $sql, $offset, $count);
+    }
+
+    /**
+     * Check if the adapter supports real SQL parameters.
+     *
+     * @param string $type 'positional' or 'named'
+     * @return bool
+     */
+    public function supportsParameters($type)
+    {
+        return false;
+    }
+
+    /**
+     * Retrieve server version in PHP style
+     *
+     * @return string
+     */
+    function getServerVersion()
+    {
+        return "1.0.0";
+    }
+}

+ 381 - 0
library/Zend/Test/DbStatement.php

@@ -0,0 +1,381 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once "Zend/Db/Statement/Interface.php";
+
+/**
+ * Testing Database Statement that acts as a stack to SQL resultsets.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_DbStatement implements Zend_Db_Statement_Interface
+{
+    /**
+     * @var array
+     */
+    protected $_fetchStack = array();
+
+    /**
+     * @var int
+     */
+    protected $_columnCount = 0;
+
+    /**
+     * @var int
+     */
+    protected $_rowCount = 0;
+
+    /**
+     * Create a Select statement which returns the given array of rows.
+     * 
+     * @param array $rows
+     * @return Zend_Test_DbStatement
+     */
+    static public function createSelectStatement(array $rows=array())
+    {
+        $stmt = new Zend_Test_DbStatement();
+        foreach($rows AS $row) {
+            $stmt->append($row);
+        }
+        return $stmt;
+    }
+
+    /**
+     * Create an Insert Statement
+     * 
+     * @param  int $affectedRows
+     * @return Zend_Test_DbStatement
+     */
+    static public function createInsertStatement($affectedRows=0)
+    {
+        return self::_createRowCountStatement($affectedRows);
+    }
+
+    /**
+     * Create an Delete Statement
+     *
+     * @param  int $affectedRows
+     * @return Zend_Test_DbStatement
+     */
+    static public function createDeleteStatement($affectedRows=0)
+    {
+        return self::_createRowCountStatement($affectedRows);
+    }
+
+    /**
+     * Create an Update Statement
+     *
+     * @param  int $affectedRows
+     * @return Zend_Test_DbStatement
+     */
+    static public function createUpdateStatement($affectedRows=0)
+    {
+        return self::_createRowCountStatement($affectedRows);
+    }
+
+    /**
+     * Create a Row Count Statement
+     *
+     * @param  int $affectedRows
+     * @return Zend_Test_DbStatement
+     */
+    static protected function _createRowCountStatement($affectedRows)
+    {
+        $stmt = new Zend_Test_DbStatement();
+        $stmt->setRowCount($affectedRows);
+        return $stmt;
+    }
+
+    /**
+     * @param int $rowCount
+     */
+    public function setRowCount($rowCount)
+    {
+        $this->_rowCount = $rowCount;
+    }
+
+    /**
+     * Append a new row to the fetch stack.
+     *
+     * @param array $row
+     */
+    public function append($row)
+    {
+        $this->_columnCount = count($row);
+        $this->_fetchStack[] = $row;
+    }
+
+    /**
+     * Bind a column of the statement result set to a PHP variable.
+     *
+     * @param string $column Name the column in the result set, either by
+     *                       position or by name.
+     * @param mixed  $param  Reference to the PHP variable containing the value.
+     * @param mixed  $type   OPTIONAL
+     * @return bool
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function bindColumn($column, &$param, $type = null)
+    {
+        return true;
+    }
+
+    /**
+     * Binds a parameter to the specified variable name.
+     *
+     * @param mixed $parameter Name the parameter, either integer or string.
+     * @param mixed $variable  Reference to PHP variable containing the value.
+     * @param mixed $type      OPTIONAL Datatype of SQL parameter.
+     * @param mixed $length    OPTIONAL Length of SQL parameter.
+     * @param mixed $options   OPTIONAL Other options.
+     * @return bool
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null)
+    {
+        return true;
+    }
+
+    /**
+     * Binds a value to a parameter.
+     *
+     * @param mixed $parameter Name the parameter, either integer or string.
+     * @param mixed $value     Scalar value to bind to the parameter.
+     * @param mixed $type      OPTIONAL Datatype of the parameter.
+     * @return bool
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function bindValue($parameter, $value, $type = null)
+    {
+        return true;
+    }
+
+    /**
+     * Closes the cursor, allowing the statement to be executed again.
+     *
+     * @return bool
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function closeCursor()
+    {
+        return true;
+    }
+
+    /**
+     * Returns the number of columns in the result set.
+     * Returns null if the statement has no result set metadata.
+     *
+     * @return int The number of columns.
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function columnCount()
+    {
+        return $this->_columnCount;
+    }
+
+    /**
+     * Retrieves the error code, if any, associated with the last operation on
+     * the statement handle.
+     *
+     * @return string error code.
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function errorCode()
+    {
+        return false;
+    }
+
+    /**
+     * Retrieves an array of error information, if any, associated with the
+     * last operation on the statement handle.
+     *
+     * @return array
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function errorInfo()
+    {
+        return false;
+    }
+
+    /**
+     * Executes a prepared statement.
+     *
+     * @param array $params OPTIONAL Values to bind to parameter placeholders.
+     * @return bool
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function execute(array $params = array())
+    {
+        return true;
+    }
+
+    /**
+     * Fetches a row from the result set.
+     *
+     * @param int $style  OPTIONAL Fetch mode for this fetch operation.
+     * @param int $cursor OPTIONAL Absolute, relative, or other.
+     * @param int $offset OPTIONAL Number for absolute or relative cursors.
+     * @return mixed Array, object, or scalar depending on fetch mode.
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function fetch($style = null, $cursor = null, $offset = null)
+    {
+        if(count($this->_fetchStack)) {
+            $row = array_shift($this->_fetchStack);
+            return $row;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Returns an array containing all of the result set rows.
+     *
+     * @param int $style OPTIONAL Fetch mode.
+     * @param int $col   OPTIONAL Column number, if fetch mode is by column.
+     * @return array Collection of rows, each in a format by the fetch mode.
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function fetchAll($style = null, $col = null)
+    {
+        $rows = $this->_fetchStack;
+        $this->_fetchStack = array();
+
+        return $rows;
+    }
+
+    /**
+     * Returns a single column from the next row of a result set.
+     *
+     * @param int $col OPTIONAL Position of the column to fetch.
+     * @return string
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function fetchColumn($col = 0)
+    {
+        $row = $this->fetch();
+
+        if($row == false) {
+            return false;
+        } else {
+            if(count($row) < $col) {
+                require_once "Zend/Db/Statement/Exception.php";
+                throw new Zend_Db_Statement_Exception(
+                    "Column Position '".$col."' is out of bounds."
+                );
+            }
+
+            $keys = array_keys($row);
+            return $row[$keys[$col]];
+        }
+    }
+
+    /**
+     * Fetches the next row and returns it as an object.
+     *
+     * @param string $class  OPTIONAL Name of the class to create.
+     * @param array  $config OPTIONAL Constructor arguments for the class.
+     * @return mixed One object instance of the specified class.
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function fetchObject($class = 'stdClass', array $config = array())
+    {
+        if(!class_exists($class)) {
+            throw new Zend_Db_Statement_Exception("Class '".$class."' does not exist!");
+        }
+
+        $object = new $class();
+        $row = $this->fetch();
+        foreach($row AS $k => $v) {
+            $object->$k = $v;
+        }
+
+        return $object;
+    }
+
+    /**
+     * Retrieve a statement attribute.
+     *
+     * @param string $key Attribute name.
+     * @return mixed      Attribute value.
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function getAttribute($key)
+    {
+        return false;
+    }
+
+    /**
+     * Retrieves the next rowset (result set) for a SQL statement that has
+     * multiple result sets.  An example is a stored procedure that returns
+     * the results of multiple queries.
+     *
+     * @return bool
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function nextRowset()
+    {
+        return false;
+    }
+
+    /**
+     * Returns the number of rows affected by the execution of the
+     * last INSERT, DELETE, or UPDATE statement executed by this
+     * statement object.
+     *
+     * @return int     The number of rows affected.
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function rowCount()
+    {
+        return $this->_rowCount;
+    }
+
+    /**
+     * Set a statement attribute.
+     *
+     * @param string $key Attribute name.
+     * @param mixed  $val Attribute value.
+     * @return bool
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function setAttribute($key, $val)
+    {
+        return true;
+    }
+
+    /**
+     * Set the default fetch mode for this statement.
+     *
+     * @param int   $mode The fetch mode.
+     * @return bool
+     * @throws Zend_Db_Statement_Exception
+     */
+    public function setFetchMode($mode)
+    {
+        return true;
+    }
+}

+ 151 - 0
library/Zend/Test/PHPUnit/DatabaseTestCase.php

@@ -0,0 +1,151 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see PHPUnit_Extensions_Database_TestCase
+ */
+require_once "PHPUnit/Extensions/Database/TestCase.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_Operation_Truncate
+ */
+require_once "Zend/Test/PHPUnit/Db/Operation/Truncate.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_Operation_Insert
+ */
+require_once "Zend/Test/PHPUnit/Db/Operation/Insert.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet
+ */
+require_once "Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_DataSet_DbTable
+ */
+require_once "Zend/Test/PHPUnit/Db/DataSet/DbTable.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_DataSet_DbRowset
+ */
+require_once "Zend/Test/PHPUnit/Db/DataSet/DbRowset.php";
+
+/**
+ * Generic Testcase for Zend Framework related DbUnit Testing with PHPUnit
+ *
+ * @uses       PHPUnit_Extensions_Database_TestCase
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+abstract class Zend_Test_PHPUnit_DatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
+{
+    /**
+     * Creates a new Zend Database Connection using the given Adapter and database schema name.
+     *
+     * @param  Zend_Db_Adapter_Abstract $connection
+     * @param  string $schema
+     * @return Zend_Test_PHPUnit_Db_Connection
+     */
+    protected function createZendDbConnection(Zend_Db_Adapter_Abstract $connection, $schema)
+    {
+        return new Zend_Test_PHPUnit_Db_Connection($connection, $schema);
+    }
+
+    /**
+     * Convenience function to get access to the database connection.
+     * 
+     * @return Zend_Db_Adapter_Abstract
+     */
+    protected function getAdapter()
+    {
+        return $this->getConnection()->getConnection();
+    }
+
+    /**
+     * Returns the database operation executed in test setup.
+     *
+     * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation
+     */
+    protected function getSetUpOperation()
+    {
+        return new PHPUnit_Extensions_Database_Operation_Composite(array(
+            new Zend_Test_PHPUnit_Db_Operation_Truncate(),
+            new Zend_Test_PHPUnit_Db_Operation_Insert(),
+        ));
+    }
+
+    /**
+     * Returns the database operation executed in test cleanup.
+     *
+     * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation
+     */
+    protected function getTearDownOperation()
+    {
+        return PHPUnit_Extensions_Database_Operation_Factory::NONE();
+    }
+
+    /**
+     * Create a dataset based on multiple Zend_Db_Table instances
+     *
+     * @param  array $tables
+     * @return Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet
+     */
+    protected function createDbTableDataSet(array $tables=array())
+    {
+        $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
+        foreach($tables AS $table) {
+            $dataSet->addTable($table);
+        }
+        return $dataSet;
+    }
+
+    /**
+     * Create a table based on one Zend_Db_Table instance
+     *
+     * @param Zend_Db_Table_Abstract $table
+     * @param string $where
+     * @param string $order
+     * @param string $count
+     * @param string $offset
+     * @return Zend_Test_PHPUnit_Db_DataSet_DbTable
+     */
+    protected function createDbTable(Zend_Db_Table_Abstract $table, $where=null, $order=null, $count=null, $offset=null)
+    {
+        return new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $where, $order, $count, $offset);
+    }
+
+    /**
+     * Create a data table based on a Zend_Db_Table_Rowset instance
+     *
+     * @param  Zend_Db_Table_Rowset_Abstract $rowset
+     * @param  string
+     * @return Zend_Test_PHPUnit_Db_DataSet_DbRowset
+     */
+    protected function createDbRowset(Zend_Db_Table_Rowset_Abstract $rowset, $tableName = null)
+    {
+        return new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset, $tableName);
+    }
+}

+ 149 - 0
library/Zend/Test/PHPUnit/Db/Connection.php

@@ -0,0 +1,149 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
+ */
+require_once "PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_DataSet_QueryTable
+ */
+require_once "Zend/Test/PHPUnit/Db/DataSet/QueryTable.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_Metadata_Generic
+ */
+require_once "Zend/Test/PHPUnit/Db/Metadata/Generic.php";
+
+/**
+ * Generic Abstraction of Zend_Db Connections in the PHPUnit Database Extension context.
+ *
+ * @uses       Zend_Db_Adapter_Abstract
+ * @uses       PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Connection extends PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
+{
+    /**
+     * Zend_Db_Adapter_Abstract
+     * 
+     * @var Zend_Db_Adapter_Abstract
+     */
+    protected $_connection;
+
+    /**
+     * Database Schema
+     *
+     * @var string $db
+     */
+    protected $_schema;
+
+    /**
+     * Metadata
+     *
+     * @param PHPUnit_Extensions_Database_DB_IMetaData $db
+     */
+    protected $_metaData;
+
+    /**
+     * Construct Connection based on Zend_Db_Adapter_Abstract
+     * 
+     * @param Zend_Db_Adapter_Abstract $db
+     * @param string $schema
+     */
+    public function __construct(Zend_Db_Adapter_Abstract $db, $schema)
+    {
+        $this->_connection = $db;
+        $this->_schema = $schema;
+    }
+
+    /**
+     * Close this connection.
+     *
+     * @return void
+     */
+    public function close()
+    {
+        $this->_connection->closeConnection();
+    }
+
+    /**
+     * Creates a table with the result of the specified SQL statement.
+     *
+     * @param string $resultName
+     * @param string $sql
+     * @return PHPUnit_Extensions_Database_DataSet_ITable
+     */
+    public function createQueryTable($resultName, $sql)
+    {
+        return new Zend_Test_PHPUnit_Db_DataSet_QueryTable($resultName, $sql, $this);
+    }
+
+    /**
+     * Returns a Zend_Db Connection
+     *
+     * @return Zend_Db_Adapter_Abstract
+     */
+    public function getConnection()
+    {
+        return $this->_connection;
+    }
+
+    /**
+     * Returns a database metadata object that can be used to retrieve table
+     * meta data from the database.
+     *
+     * @return PHPUnit_Extensions_Database_DB_IMetaData
+     */
+    public function getMetaData()
+    {
+        if($this->_metaData === null) {
+            $this->_metaData = new Zend_Test_PHPUnit_Db_Metadata_Generic($this->getConnection(), $this->getSchema());
+        }
+        return $this->_metaData;
+    }
+
+    /**
+     * Returns the schema for the connection.
+     *
+     * @return string
+     */
+    public function getSchema()
+    {
+        return $this->_schema;
+    }
+
+    /**
+     * Returns the command used to truncate a table.
+     *
+     * @return string
+     */
+    public function getTruncateCommand()
+    {
+        return "DELETE";
+    }
+}

+ 75 - 0
library/Zend/Test/PHPUnit/Db/DataSet/DbRowset.php

@@ -0,0 +1,75 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Db_Table_Rowset_Abstract
+ */
+require_once "Zend/Db/Table/Rowset/Abstract.php";
+
+require_once "PHPUnit/Extensions/Database/DataSet/AbstractTable.php";
+
+/**
+ * Use a Zend_Db Rowset as a datatable for assertions with other PHPUnit Database extension tables.
+ *
+ * @uses       PHPUnit_Extensions_Database_DataSet_AbstractTable
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_DbRowset extends PHPUnit_Extensions_Database_DataSet_AbstractTable
+{
+    /**
+     * Construct Table object from a Zend_Db_Table_Rowset
+     * 
+     * @param Zend_Db_Table_Rowset_Abstract $rowset
+     * @param string $tableName
+     */
+    public function __construct(Zend_Db_Table_Rowset_Abstract $rowset, $tableName = null)
+    {
+        if($tableName == null) {
+            $table = $rowset->getTable();
+            if($table !== null) {
+                $tableName = $table->info('name');
+            } else {
+                require_once "Zend/Test/PHPUnit/Db/Exception.php";
+                throw new Zend_Test_PHPUnit_Db_Exception(
+                    'No table name was given to Rowset Table and table name cannot be infered from the table, '.
+                    'because the rowset is disconnected from database.'
+                );
+            }
+        }
+
+        $this->data = $rowset->toArray();
+
+        $columns = array();
+        if(isset($this->data[0]) > 0) {
+            $columns = array_keys($this->data[0]);
+        } else if($rowset->getTable() != null) {
+            $columns = $rowset->getTable()->info('cols');
+        }
+
+        $this->tableName = $tableName;
+        $this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $columns);
+    }
+}

+ 123 - 0
library/Zend/Test/PHPUnit/Db/DataSet/DbTable.php

@@ -0,0 +1,123 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+
+require_once "PHPUnit/Extensions/Database/DataSet/QueryTable.php";
+
+/**
+ * @see Zend_Db_Table_Abstract
+ */
+require_once "Zend/Db/Table/Abstract.php";
+
+/**
+ * Use a Zend_Db_Table for assertions with other PHPUnit Database Extension table types.
+ *
+ * @uses       PHPUnit_Extensions_Database_DataSet_QueryTable
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_DbTable extends PHPUnit_Extensions_Database_DataSet_QueryTable
+{
+    /**
+     * Zend_Db_Table object
+     * 
+     * @var Zend_Db_Table_Abstract
+     */
+    protected $_table = null;
+
+    /**
+     * @var array
+     */
+    protected $_columns = array();
+
+    /**
+     * @var string
+     */
+    protected $_where = null;
+
+    /**
+     * @var string
+     */
+    protected $_orderBy = null;
+
+    /**
+     * @var string
+     */
+    protected $_count = null;
+
+    /**
+     * @var int
+     */
+    protected $_offset = null;
+
+    /**
+     * Construct Dataset Table from Zend_Db_Table object
+     *
+     * @param Zend_Db_Table_Abstract        $table
+     * @param string|Zend_Db_Select|null    $where
+     * @param string|null                   $order
+     * @param int                           $count
+     * @param int                           $offset
+     */
+    public function __construct(Zend_Db_Table_Abstract $table, $where=null, $order=null, $count=null, $offset=null)
+    {
+        $this->tableName = $table->info('name');
+        $this->_columns = $table->info('cols');
+
+        $this->_table = $table;
+        $this->_where = $where;
+        $this->_order = $order;
+        $this->_count = $count;
+        $this->_offset = $offset;
+    }
+
+    /**
+     * Lazy load data via table fetchAll() method.
+     *
+     * @return void
+     */
+    protected function loadData()
+    {
+        if ($this->data === null) {
+            $this->data = $this->_table->fetchAll(
+                $this->_where, $this->_order, $this->_count, $this->_offset
+            );
+            if($this->data instanceof Zend_Db_Table_Rowset_Abstract) {
+                $this->data = $this->data->toArray();
+            }
+        }
+    }
+
+    /**
+     * Create Table Metadata object
+     */
+    protected function createTableMetaData()
+    {
+        if ($this->tableMetaData === NULL) {
+            $this->loadData();
+            $this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $this->_columns);
+        }
+    }
+}

+ 103 - 0
library/Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php

@@ -0,0 +1,103 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once "PHPUnit/Extensions/Database/DataSet/QueryDataSet.php";
+
+require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_DataSet_DbTable
+ */
+require_once "Zend/Test/PHPUnit/Db/DataSet/DbTable.php";
+
+/**
+ * Aggregate several Zend_Db_Table instances into a dataset.
+ *
+ * @uses       Zend_Db_Table
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet
+{
+    /**
+     * @var array
+     */
+    protected $tables = array();
+
+    /**
+     * Add a Table dataset representation by specifiying an arbitrary select query.
+     *
+     * By default a select * will be done on the given tablename.
+     *
+     * @param Zend_Db_Table_Abstract $table
+     * @param string|Zend_Db_Select $query
+     * @param string $where
+     * @param string $order
+     * @param string $count
+     * @param string $offset
+     */
+    public function addTable(Zend_Db_Table_Abstract $table, $where = null, $order = null, $count = null, $offset = null)
+    {
+        $tableName = $table->info('name');
+        $this->tables[$tableName] = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $where, $order, $count, $offset);
+    }
+
+    /**
+     * Creates an iterator over the tables in the data set. If $reverse is
+     * true a reverse iterator will be returned.
+     *
+     * @param bool $reverse
+     * @return PHPUnit_Extensions_Database_DB_TableIterator
+     */
+    protected function createIterator($reverse = FALSE)
+    {
+        return new PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($this->tables, $reverse);
+    }
+
+    /**
+     * Returns a table object for the given table.
+     *
+     * @param string $tableName
+     * @return PHPUnit_Extensions_Database_DB_Table
+     */
+    public function getTable($tableName)
+    {
+        if (!isset($this->tables[$tableName])) {
+            throw new InvalidArgumentException("$tableName is not a table in the current database.");
+        }
+
+        return $this->tables[$tableName];
+    }
+
+    /**
+     * Returns a list of table names for the database
+     *
+     * @return Array
+     */
+    public function getTableNames()
+    {
+        return array_keys($this->tables);
+    }
+}

+ 86 - 0
library/Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php

@@ -0,0 +1,86 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once "PHPUnit/Extensions/Database/DataSet/QueryDataSet.php";
+
+require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_DataSet_QueryTable
+ */
+require_once "Zend/Test/PHPUnit/Db/DataSet/QueryTable.php";
+
+
+
+/**
+ * @see Zend_Db_Select
+ */
+require_once "Zend/Db/Select.php";
+
+/**
+ * Uses several query strings or Zend_Db_Select objects to form a dataset of tables for assertion with other datasets.
+ *
+ * @uses       PHPUnit_Extensions_Database_DataSet_QueryDataSet
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_QueryDataSet extends PHPUnit_Extensions_Database_DataSet_QueryDataSet
+{
+    /**
+     * Creates a new dataset using the given database connection.
+     *
+     * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection
+     */
+    public function __construct(PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection)
+    {
+        if( !($databaseConnection instanceof Zend_Test_PHPUnit_Db_Connection) ) {
+            require_once "Zend/Test/PHPUnit/Db/Exception.php";
+            throw new Zend_Test_PHPUnit_Db_Exception("Zend_Test_PHPUnit_Db_DataSet_QueryDataSet only works with Zend_Test_PHPUnit_Db_Connection connections-");
+        }
+        $this->databaseConnection = $databaseConnection;
+    }
+
+    /**
+     * Add a Table dataset representation by specifiying an arbitrary select query.
+     *
+     * By default a select * will be done on the given tablename.
+     *
+     * @param string                $tableName
+     * @param string|Zend_Db_Select $query
+     */
+    public function addTable($tableName, $query = NULL)
+    {
+        if ($query === NULL) {
+            $query = $this->databaseConnection->getConnection()->select();
+            $query->from($tableName, Zend_Db_Select::SQL_WILDCARD);
+        }
+
+        if($query instanceof Zend_Db_Select) {
+            $query = $query->__toString();
+        }
+
+        $this->tables[$tableName] = new Zend_Test_PHPUnit_Db_DataSet_QueryTable($tableName, $query, $this->databaseConnection);
+    }
+}

+ 68 - 0
library/Zend/Test/PHPUnit/Db/DataSet/QueryTable.php

@@ -0,0 +1,68 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+
+require_once "PHPUnit/Extensions/Database/DataSet/QueryTable.php";
+
+require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
+
+/**
+ * Represent a PHPUnit Database Extension table with Queries using a Zend_Db adapter for assertion against other tables.
+ *
+ * @uses       PHPUnit_Extensions_Database_DataSet_QueryTable
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_QueryTable extends PHPUnit_Extensions_Database_DataSet_QueryTable
+{
+    /**
+     * Creates a new database query table object.
+     *
+     * @param string $table_name
+     * @param string $query
+     * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection
+     */
+    public function __construct($tableName, $query, PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection)
+    {
+        if( !($databaseConnection instanceof Zend_Test_PHPUnit_Db_Connection) ) {
+            require_once "Zend/Test/PHPUnit/Db/Exception.php";
+            throw new Zend_Test_PHPUnit_Db_Exception("Zend_Test_PHPUnit_Db_DataSet_QueryTable only works with Zend_Test_PHPUnit_Db_Connection connections-");
+        }
+        parent::__construct($tableName, $query, $databaseConnection);
+    }
+
+    /**
+     * Load data from the database.
+     *
+     * @return void
+     */
+    protected function loadData()
+    {
+        if($this->data === null) {
+            $stmt = $this->databaseConnection->getConnection()->query($this->query);
+            $this->data = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
+        }
+    }
+}

+ 41 - 0
library/Zend/Test/PHPUnit/Db/Exception.php

@@ -0,0 +1,41 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Exception
+ */
+require_once "Zend/Exception.php";
+
+/**
+ * Exception for Zend_Test_PHPUnit_Database package
+ *
+ * @uses       Zend_Exception
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Exception extends Zend_Exception
+{
+    
+}

+ 164 - 0
library/Zend/Test/PHPUnit/Db/Metadata/Generic.php

@@ -0,0 +1,164 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see Zend_Db_Adapter_Abstract
+ */
+require_once "Zend/Db/Adapter/Abstract.php";
+
+require_once "PHPUnit/Extensions/Database/DB/IMetaData.php";
+
+/**
+ * Generic Metadata accessor for the Zend_Db adapters
+ *
+ * @uses       PHPUnit_Extensions_Database_DB_IMetaData
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Metadata_Generic implements PHPUnit_Extensions_Database_DB_IMetaData
+{
+    /**
+     * Zend_Db Connection
+     * 
+     * @var Zend_Db_Adapter_Abstract
+     */
+    protected $_connection;
+
+    /**
+     * Schemaname
+     *
+     * @var string
+     */
+    protected $_schema;
+
+    /**
+     * Cached Table metadata
+     * 
+     * @var array
+     */
+    protected $_tableMetadata = array();
+
+    /**
+     * Creates a new database meta data object using the given pdo connection
+     * and schema name.
+     *
+     * @param PDO $pdo
+     * @param string $schema
+     */
+    public final function __construct(Zend_Db_Adapter_Abstract $db, $schema)
+    {
+        $this->_connection = $db;
+        $this->_schema     = $schema;
+    }
+
+    /**
+     * List Tables
+     * 
+     * @return array
+     */
+    public function getTableNames()
+    {
+        return $this->_connection->listTables();
+    }
+
+    /**
+     * Get Table information
+     * 
+     * @param  string $tableName
+     * @return array
+     */
+    protected function getTableDescription($tableName)
+    {
+        if(!isset($this->_tableMetadata[$tableName])) {
+            $this->_tableMetadata[$tableName] = $this->_connection->describeTable($tableName);
+        }
+        return $this->_tableMetadata[$tableName];
+    }
+
+    /**
+     * Returns an array containing the names of all the columns in the
+     * $tableName table,
+     *
+     * @param string $tableName
+     * @return array
+     */
+    public function getTableColumns($tableName)
+    {
+        $tableMeta = $this->getTableDescription($tableName);
+        $columns = array_keys($tableMeta);
+        return $columns;
+    }
+
+    /**
+     * Returns an array containing the names of all the primary key columns in
+     * the $tableName table.
+     *
+     * @param string $tableName
+     * @return array
+     */
+    public function getTablePrimaryKeys($tableName)
+    {
+        $tableMeta = $this->getTableDescription($tableName);
+
+        $primaryColumnNames = array();
+        foreach($tableMeta AS $column) {
+            if($column['PRIMARY'] == true) {
+                $primaryColumnNames[] = $column['COLUMN_NAME'];
+            }
+        }
+        return $primaryColumnNames;
+    }
+
+    /**
+     * Returns the name of the default schema.
+     *
+     * @return string
+     */
+    public function getSchema()
+    {
+        return $this->_schema;
+    }
+
+    /**
+     * Returns a quoted schema object. (table name, column name, etc)
+     *
+     * @param string $object
+     * @return string
+     */
+    public function quoteSchemaObject($object)
+    {
+        return $this->_connection->quoteIdentifier($object);
+    }
+
+    /**
+     * Returns true if the rdbms allows cascading
+     *
+     * @return bool
+     */
+    public function allowsCascading()
+    {
+        return false;
+    }
+}

+ 69 - 0
library/Zend/Test/PHPUnit/Db/Operation/DeleteAll.php

@@ -0,0 +1,69 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once "PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php";
+
+require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
+
+require_once "PHPUnit/Extensions/Database/DataSet/IDataSet.php";
+
+require_once "PHPUnit/Extensions/Database/Operation/Exception.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_Connection
+ */
+require_once "Zend/Test/PHPUnit/Db/Connection.php";
+
+/**
+ * Delete All Operation that can be executed on set up or tear down of a database tester.
+ *
+ * @uses       PHPUnit_Extensions_Database_Operation_IDatabaseOperation
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Operation_DeleteAll implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
+{
+    /**
+     * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
+     * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
+     */
+    public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
+    {
+        if(!($connection instanceof Zend_Test_PHPUnit_Db_Connection)) {
+            require_once "Zend/Test/PHPUnit/Db/Exception.php";
+            throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
+        }
+
+        foreach ($dataSet as $table) {
+            try {
+                $tableName = $table->getTableMetaData()->getTableName();
+                $connection->getConnection()->delete($tableName);
+            } catch (Exception $e) {
+                require_once "PHPUnit/Extensions/Database/Operation/Exception.php";
+                throw new PHPUnit_Extensions_Database_Operation_Exception('DELETEALL', 'DELETE FROM '.$tableName.'', array(), $table, $e->getMessage());
+            }
+        }
+    }
+}

+ 92 - 0
library/Zend/Test/PHPUnit/Db/Operation/Insert.php

@@ -0,0 +1,92 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once "PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php";
+
+require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
+
+require_once "PHPUnit/Extensions/Database/DataSet/IDataSet.php";
+
+require_once "PHPUnit/Extensions/Database/Operation/Exception.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_Connection
+ */
+require_once "Zend/Test/PHPUnit/Db/Connection.php";
+
+/**
+ * Operation for Inserting on setup or teardown of a database tester.
+ *
+ * @uses       PHPUnit_Extensions_Database_Operation_IDatabaseOperation
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Operation_Insert implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
+{
+    /**
+     * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
+     * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
+     */
+    public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
+    {
+        if(!($connection instanceof Zend_Test_PHPUnit_Db_Connection)) {
+            require_once "Zend/Test/PHPUnit/Db/Exception.php";
+            throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
+        }
+
+        $databaseDataSet = $connection->createDataSet();
+
+        $dsIterator = $dataSet->getIterator();
+
+        foreach($dsIterator as $table) {
+            $tableName = $table->getTableMetaData()->getTableName();
+
+            $db = $connection->getConnection();
+            for($i = 0; $i < $table->getRowCount(); $i++) {
+                $values = $this->buildInsertValues($table, $i);
+                try {
+                    $db->insert($tableName, $values);
+                } catch (Exception $e) {
+                    throw new PHPUnit_Extensions_Database_Operation_Exception("INSERT", "INSERT INTO ".$tableName." [..]", $values, $table, $e->getMessage());
+                }
+            }
+        }
+    }
+
+    /**
+     *
+     * @param PHPUnit_Extensions_Database_DataSet_ITable $table
+     * @param int $rowNum
+     * @return array
+     */
+    protected function buildInsertValues(PHPUnit_Extensions_Database_DataSet_ITable $table, $rowNum)
+    {
+        $values = array();
+        foreach($table->getTableMetaData()->getColumns() as $columnName) {
+            $values[$columnName] = $table->getValue($rowNum, $columnName);
+        }
+        return $values;
+    }
+}

+ 98 - 0
library/Zend/Test/PHPUnit/Db/Operation/Truncate.php

@@ -0,0 +1,98 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once "PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php";
+
+require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
+
+require_once "PHPUnit/Extensions/Database/DataSet/IDataSet.php";
+
+require_once "PHPUnit/Extensions/Database/Operation/Exception.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_Connection
+ */
+require_once "Zend/Test/PHPUnit/Db/Connection.php";
+
+/**
+ * Operation for Truncating on setup or teardown of a database tester.
+ *
+ * @uses       PHPUnit_Extensions_Database_Operation_IDatabaseOperation
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Operation_Truncate implements PHPUnit_Extensions_Database_Operation_IDatabaseOperation
+{
+    /**
+     *
+     * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
+     * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
+     * @return void
+     */
+    public function execute(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection, PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
+    {
+        if(!($connection instanceof Zend_Test_PHPUnit_Db_Connection)) {
+            require_once "Zend/Test/PHPUnit/Db/Exception.php";
+            throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
+        }
+
+        foreach ($dataSet as $table) {
+            try {
+                $tableName = $table->getTableMetaData()->getTableName();
+                $this->truncate($connection->getConnection(), $tableName);
+            } catch (Exception $e) {
+                throw new PHPUnit_Extensions_Database_Operation_Exception('TRUNCATE', 'TRUNCATE '.$tableName.'', array(), $table, $e->getMessage());
+            }
+        }
+    }
+
+    /**
+     * Truncate a given table.
+     * 
+     * @param Zend_Db_Adapter_Abstract $db
+     * @param string $tableName
+     * @return void
+     */
+    private function truncate(Zend_Db_Adapter_Abstract $db, $tableName)
+    {
+        $tableName = $db->quoteIdentifier($tableName);
+        if($db instanceof Zend_Db_Adapter_Pdo_Sqlite) {
+            $db->query('DELETE FROM '.$tableName);
+        } else if($db instanceof Zend_Db_Adapter_Db2) {
+            if(strstr(PHP_OS, "WIN")) {
+                $file = tempnam(sys_get_temp_dir(), "zendtestdbibm_");
+                file_put_contents($file, "");
+                $db->query('IMPORT FROM '.$file.' OF DEL REPLACE INTO '.$tableName);
+                unlink($file);
+            } else {
+                $db->query('IMPORT FROM /dev/null OF DEL REPLACE INTO '.$tableName);
+            }
+        } else if($db instanceof Zend_Db_Adapter_Pdo_Mssql) {
+            $db->query('TRUNCATE TABLE '.$tableName);
+        } else {
+            $db->query('TRUNCATE '.$tableName);
+        }
+    }
+}

+ 95 - 0
library/Zend/Test/PHPUnit/Db/SimpleTester.php

@@ -0,0 +1,95 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+/**
+ * @see PHPUnit_Extensions_Database_DefaultTester
+ */
+require_once "PHPUnit/Extensions/Database/DefaultTester.php";
+
+/**
+ * @see PHPUnit_Extensions_Database_DB_IDatabaseConnection
+ */
+require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_Operation_Truncate
+ */
+require_once "Zend/Test/PHPUnit/Db/Operation/Truncate.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_Operation_Insert
+ */
+require_once "Zend/Test/PHPUnit/Db/Operation/Insert.php";
+
+/**
+ * @see PHPUnit_Extensions_Database_Operation_Factory
+ */
+require_once "PHPUnit/Extensions/Database/Operation/Factory.php";
+
+/**
+ * @see PHPUnit_Extensions_Database_DataSet_IDataSet
+ */
+require_once "PHPUnit/Extensions/Database/DataSet/IDataSet.php";
+
+/**
+ * Simple Tester for Database Tests when the Abstract Test Case cannot be used.
+ *
+ * @uses       PHPUnit_Extensions_Database_DefaultTester
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage PHPUnit
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_SimpleTester extends PHPUnit_Extensions_Database_DefaultTester
+{
+    /**
+     * Creates a new default database tester using the given connection.
+     *
+     * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection
+     */
+    public function __construct(PHPUnit_Extensions_Database_DB_IDatabaseConnection $connection)
+    {
+        if(!($connection instanceof Zend_Test_PHPUnit_Db_Connection)) {
+            require_once "Zend/Test/PHPUnit/Db/Exception.php";
+            throw new Zend_Test_PHPUnit_Db_Exception("Not a valid Zend_Test_PHPUnit_Db_Connection instance, ".get_class($connection)." given!");
+        }
+
+        $this->connection = $connection;
+        $this->setUpOperation = new PHPUnit_Extensions_Database_Operation_Composite(array(
+            new Zend_Test_PHPUnit_Db_Operation_Truncate(),
+            new Zend_Test_PHPUnit_Db_Operation_Insert(),
+        ));
+        $this->tearDownOperation = PHPUnit_Extensions_Database_Operation_Factory::NONE();
+    }
+
+    /**
+     * Set Up the database using the given Dataset and the SetUp strategy "Truncate, then Insert"
+     *
+     * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet
+     */
+    public function setUpDatabase(PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet)
+    {
+        $this->setDataSet($dataSet);
+        $this->onSetUp();
+    }
+}

+ 4 - 0
tests/Zend/Test/AllTests.php

@@ -30,6 +30,8 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
 }
 
 require_once 'Zend/Test/PHPUnit/AllTests.php';
+require_once 'Zend/Test/DbAdapterTest.php';
+require_once 'Zend/Test/DbStatementTest.php';
 
 /**
  * @category   Zend
@@ -49,6 +51,8 @@ class Zend_Test_AllTests
     {
         $suite = new PHPUnit_Framework_TestSuite('Zend Framework - Zend_Test');
 
+        $suite->addTestSuite('Zend_Test_DbAdapterTest');
+        $suite->addTestSuite('Zend_Test_DbStatementTest');
         $suite->addTest(Zend_Test_PHPUnit_AllTests::suite());
 
         return $suite;

+ 111 - 0
tests/Zend/Test/DbAdapterTest.php

@@ -0,0 +1,111 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../TestHelper.php";
+
+require_once "Zend/Test/DbAdapter.php";
+require_once "Zend/Test/DbStatement.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_DbAdapterTest extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Zend_Test_DbAdapter
+     */
+    private $_adapter = null;
+
+    public function setUp()
+    {
+        $this->_adapter = new Zend_Test_DbAdapter();
+    }
+
+    public function testAppendStatementToStack()
+    {
+        $stmt1 = Zend_Test_DbStatement::createSelectStatement( array() );
+        $this->_adapter->appendStatementToStack($stmt1);
+
+        $stmt2 = Zend_Test_DbStatement::createSelectStatement( array() );
+        $this->_adapter->appendStatementToStack($stmt2);
+
+        $this->assertSame($stmt2, $this->_adapter->query("foo"));
+        $this->assertSame($stmt1, $this->_adapter->query("foo"));
+    }
+
+    public function testAppendLastInsertId()
+    {
+        $this->_adapter->appendLastInsertIdToStack(1);
+        $this->_adapter->appendLastInsertIdToStack(2);
+
+        $this->assertEquals(2, $this->_adapter->lastInsertId());
+        $this->assertEquals(1, $this->_adapter->lastInsertId());
+    }
+
+    public function testLastInsertIdDefault()
+    {
+        $this->assertFalse($this->_adapter->lastInsertId());
+    }
+
+    public function testListTablesDefault()
+    {
+        $this->assertEquals(array(), $this->_adapter->listTables());
+    }
+
+    public function testSetListTables()
+    {
+        $this->_adapter->setListTables(array("foo", "bar"));
+        $this->assertEquals(array("foo", "bar"), $this->_adapter->listTables());
+    }
+
+    public function testDescribeTableDefault()
+    {
+        $this->assertEquals(array(), $this->_adapter->describeTable("foo"));
+    }
+
+    public function testDescribeTable()
+    {
+        $this->_adapter->setDescribeTable("foo", array("bar"));
+        $this->assertEquals(array("bar"), $this->_adapter->describeTable("foo"));
+    }
+
+    public function testConnect()
+    {
+        $this->assertFalse($this->_adapter->isConnected());
+        $this->_adapter->query("foo");
+        $this->assertTrue($this->_adapter->isConnected());
+        $this->_adapter->closeConnection();
+        $this->assertFalse($this->_adapter->isConnected());
+    }
+
+    public function testAppendLimitToSql()
+    {
+        $sql = $this->_adapter->limit("foo", 10, 20);
+        $this->assertEquals(
+            "foo LIMIT 20,10", $sql
+        );
+    }
+}

+ 165 - 0
tests/Zend/Test/DbStatementTest.php

@@ -0,0 +1,165 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../TestHelper.php";
+
+require_once "Zend/Test/DbAdapter.php";
+require_once "Zend/Test/DbStatement.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_DbStatementTest extends PHPUnit_Framework_TestCase
+{
+    public function testRowCountDefault()
+    {
+        $stmt = new Zend_Test_DbStatement();
+        $this->assertEquals(0, $stmt->rowCount());
+    }
+
+    public function testSetRowCount()
+    {
+        $stmt = new Zend_Test_DbStatement();
+        $stmt->setRowCount(10);
+        $this->assertEquals(10, $stmt->rowCount());
+    }
+
+    public function testCreateSelectStatementWithRows()
+    {
+        $rows = array("foo", "bar");
+
+        $stmt = Zend_Test_DbStatement::createSelectStatement($rows);
+
+        $this->assertType('Zend_Test_DbStatement', $stmt);
+        $this->assertEquals($rows, $stmt->fetchAll());
+    }
+
+    public function testCreateInsertStatementWithRowCount()
+    {
+        $stmt = Zend_Test_DbStatement::createInsertStatement(1234);
+
+        $this->assertType('Zend_Test_DbStatement', $stmt);
+        $this->assertEquals(1234, $stmt->rowCount());
+    }
+
+    public function testCreateUpdateStatementWithRowCount()
+    {
+        $stmt = Zend_Test_DbStatement::createUpdateStatement(1234);
+
+        $this->assertType('Zend_Test_DbStatement', $stmt);
+        $this->assertEquals(1234, $stmt->rowCount());
+    }
+
+    public function testCreateDeleteStatementWithRowCount()
+    {
+        $stmt = Zend_Test_DbStatement::createDeleteStatement(1234);
+
+        $this->assertType('Zend_Test_DbStatement', $stmt);
+        $this->assertEquals(1234, $stmt->rowCount());
+    }
+
+    public function testSetFetchRow()
+    {
+        $row = array("foo");
+
+        $stmt = new Zend_Test_DbStatement();
+        $stmt->append($row);
+
+        $this->assertEquals($row, $stmt->fetch());
+    }
+
+    public function testFetchDefault()
+    {
+        $stmt = new Zend_Test_DbStatement();
+        $this->assertFalse($stmt->fetch());
+    }
+
+    public function testFetchResult_FromEmptyResultStack()
+    {
+        $row = array("foo");
+
+        $stmt = new Zend_Test_DbStatement();
+        $stmt->append($row);
+        $stmt->append($row);
+
+        $this->assertTrue($stmt->fetch() !== false);
+        $this->assertTrue($stmt->fetch() !== false);
+        $this->assertFalse($stmt->fetch());
+    }
+
+    public function testFetchColumnDefault()
+    {
+        $stmt = new Zend_Test_DbStatement();
+        $this->assertFalse($stmt->fetchColumn());
+    }
+
+    public function testFetchColumn()
+    {
+        $row = array("foo" => "bar", "bar" => "baz");
+
+        $stmt = new Zend_Test_DbStatement();
+        $stmt->append($row);
+
+        $this->assertEquals("baz", $stmt->fetchColumn(1));
+    }
+
+    public function testFetchColumn_OutOfBounds()
+    {
+        $this->setExpectedException("Zend_Db_Statement_Exception");
+
+        $row = array("foo" => "bar", "bar" => "baz");
+
+        $stmt = new Zend_Test_DbStatement();
+        $stmt->append($row);
+
+        $stmt->fetchColumn(1234);
+    }
+
+    public function testFetchObject()
+    {
+        $row = array("foo" => "bar", "bar" => "baz");
+
+        $stmt = new Zend_Test_DbStatement();
+        $stmt->append($row);
+
+        $object = $stmt->fetchObject();
+        $this->assertType('stdClass', $object);
+        $this->assertEquals('bar', $object->foo);
+        $this->assertEquals('baz', $object->bar);
+    }
+
+    public function testFetchObject_ClassNotExists_ThrowsException()
+    {
+        $this->setExpectedException("Zend_Db_Statement_Exception");
+
+        $row = array("foo" => "bar", "bar" => "baz");
+
+        $stmt = new Zend_Test_DbStatement();
+        $stmt->append($row);
+
+        $object = $stmt->fetchObject("anInvalidClassName");
+    }
+}

+ 2 - 0
tests/Zend/Test/PHPUnit/AllTests.php

@@ -30,6 +30,7 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
 }
 
 require_once 'Zend/Test/PHPUnit/ControllerTestCaseTest.php';
+require_once 'Zend/Test/PHPUnit/Db/AllTests.php';
 
 /**
  * @category   Zend
@@ -50,6 +51,7 @@ class Zend_Test_PHPUnit_AllTests
         $suite = new PHPUnit_Framework_TestSuite('Zend Framework - Zend_Test- Zend_Test_PHPUnit');
 
         $suite->addTestSuite('Zend_Test_PHPUnit_ControllerTestCaseTest');
+        $suite->addTest(Zend_Test_PHPUnit_Db_AllTests::suite());
 
         return $suite;
     }

+ 57 - 0
tests/Zend/Test/PHPUnit/Db/AllTests.php

@@ -0,0 +1,57 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../TestHelper.php";
+
+require_once "DataSet/AllTests.php";
+require_once "Operation/AllTests.php";
+require_once "Metadata/GenericTest.php";
+require_once "TestCaseTest.php";
+require_once "ConnectionTest.php";
+require_once "SimpleTesterTest.php";
+require_once "Integration/SqLiteIntegrationTest.php";
+require_once "Integration/MysqlIntegrationTest.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_AllTests
+{
+    public static function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('Zend Test PHPUnit Database Extension');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_TestCaseTest');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_ConnectionTest');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_SimpleTesterTest');
+        $suite->addTest(Zend_Test_PHPUnit_Db_DataSet_AllTests::suite());
+        $suite->addTest(Zend_Test_PHPUnit_Db_Operation_AllTests::suite());
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_Metadata_GenericTest');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_Integration_SqLiteIntegrationTest');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_Integration_MysqlIntegrationTest');
+
+        return $suite;
+    }
+}

+ 91 - 0
tests/Zend/Test/PHPUnit/Db/ConnectionTest.php

@@ -0,0 +1,91 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../TestHelper.php";
+require_once "Zend/Test/DbAdapter.php";
+require_once "Zend/Test/PHPUnit/Db/Connection.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_ConnectionTest extends PHPUnit_Framework_TestCase
+{
+    protected $adapterMock;
+
+    public function setUp()
+    {
+        $this->adapterMock = $this->getMock('Zend_Test_DbAdapter');
+    }
+
+    /**
+     * @return Zend_Test_PHPUnit_Db_Connection
+     */
+    public function createConnection()
+    {
+        $connection = new Zend_Test_PHPUnit_Db_Connection($this->adapterMock, "schema");
+        return $connection;
+    }
+
+    public function testCloseConnection()
+    {
+        $this->adapterMock->expects($this->once())
+                    ->method('closeConnection');
+
+        $connection = $this->createConnection();
+        $connection->close();
+    }
+
+    public function testCreateQueryTable()
+    {
+        $connection = $this->createConnection();
+        $ret = $connection->createQueryTable("foo", "foo");
+
+        $this->assertType('Zend_Test_PHPUnit_Db_DataSet_QueryTable', $ret);
+    }
+
+    public function testGetSchema()
+    {
+        $fixtureSchema = "schema";
+        $connection = new Zend_Test_PHPUnit_Db_Connection($this->adapterMock, $fixtureSchema);
+
+        $this->assertEquals($fixtureSchema, $connection->getSchema());
+    }
+
+    public function testGetMetaData()
+    {
+        $connection = $this->createConnection();
+        $metadata = $connection->getMetaData();
+
+        $this->assertType('Zend_Test_PHPUnit_Db_Metadata_Generic', $metadata);
+    }
+
+    public function testGetTruncateCommand()
+    {
+        $connection = $this->createConnection();
+
+        $this->assertEquals("DELETE", $connection->getTruncateCommand());
+    }
+}

+ 51 - 0
tests/Zend/Test/PHPUnit/Db/DataSet/AllTests.php

@@ -0,0 +1,51 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+require_once "DbRowsetTest.php";
+require_once "QueryDataSetTest.php";
+require_once "QueryTableTest.php";
+require_once "DbTableTest.php";
+require_once "DbTableDataSetTest.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_AllTests
+{
+    public static function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('Zend Test PHPUnit Database DataSets');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_DataSet_DbRowsetTest');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_DataSet_QueryDataSetTest');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_DataSet_QueryTableTest');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_DataSet_DbTableTest');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_DataSet_DbTableDataSetTest');
+
+        return $suite;
+    }
+}

+ 55 - 0
tests/Zend/Test/PHPUnit/Db/DataSet/DataSetTestCase.php

@@ -0,0 +1,55 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once "Zend/Test/PHPUnit/Db/Connection.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+abstract class Zend_Test_PHPUnit_Db_DataSet_DataSetTestCase extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var PHPUnit_Extensions_Database_DB_IDatabaseConnection
+     */
+    protected $connectionMock = null;
+
+    public function setUp()
+    {
+        $this->connectionMock = $this->getMock('Zend_Test_PHPUnit_Db_Connection', array(), array(), '', false);
+    }
+
+    public function decorateConnectionMockWithZendAdapter()
+    {
+        $this->decorateConnectionGetConnectionWith(new Zend_Test_DbAdapter());
+    }
+
+    public function decorateConnectionGetConnectionWith($returnValue)
+    {
+        $this->connectionMock->expects($this->any())
+                             ->method('getConnection')
+                             ->will($this->returnValue($returnValue));
+    }
+}

+ 98 - 0
tests/Zend/Test/PHPUnit/Db/DataSet/DbRowsetTest.php

@@ -0,0 +1,98 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+require_once "Zend/Test/PHPUnit/Db/DataSet/DbRowset.php";
+require_once "Zend/Db/Table/Rowset.php";
+require_once "PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_DbRowsetTest extends PHPUnit_Framework_TestCase
+{
+    protected function getRowSet()
+    {
+        $config = array(
+            'rowClass' => 'stdClass',
+            'data'     => array(array('foo' => 'bar'), array('foo' => 'baz')),
+        );
+        $rowset = new Zend_Db_Table_Rowset($config);
+        return $rowset;
+    }
+
+    public function testRowsetCountInITableRepresentation()
+    {
+        $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($this->getRowSet(), "fooTable");
+        $this->assertEquals(2, $rowsetTable->getRowCount());
+    }
+
+    public function testRowsetGetSpecificValue()
+    {
+        $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($this->getRowSet(), "fooTable");
+        $this->assertEquals("bar", $rowsetTable->getValue(0, "foo"));
+    }
+
+    public function testRowsetGetSpecificRow()
+    {
+        $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($this->getRowSet(), "fooTable");
+        $this->assertEquals(array("foo" => "baz"), $rowsetTable->getRow(1));
+    }
+
+    public function testRowset_ConstructWithDisconnectedRowset_NoTableName_ThrowsException()
+    {
+        $this->setExpectedException("Zend_Test_PHPUnit_Db_Exception");
+
+        $rowset = $this->getMock('Zend_Db_Table_Rowset_Abstract', array(), array(), '', false);
+        $rowset->expects($this->once())
+               ->method('getTable')
+               ->will($this->returnValue(null));
+
+        $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset);
+    }
+
+    public function testRowset_WithNoRows_GetColumnsFromTable()
+    {
+        $columns = array("foo", "bar");
+
+        $tableMock = $this->getMock('Zend_Db_Table_Abstract', array(), array(), '', false);
+        $tableMock->expects($this->once())
+                  ->method('info')
+                  ->with($this->equalTo('cols'))
+                  ->will($this->returnValue($columns));
+
+        $rowset = $this->getMock('Zend_Db_Table_Rowset_Abstract', array(), array(), '', false);
+        $rowset->expects($this->exactly(2))
+               ->method('getTable')
+               ->will($this->returnValue($tableMock));
+        $rowset->expects($this->once())
+               ->method('toArray')
+               ->will($this->returnValue( array() ));
+
+        $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset, "tableName");
+    }
+}

+ 72 - 0
tests/Zend/Test/PHPUnit/Db/DataSet/DbTableDataSetTest.php

@@ -0,0 +1,72 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+require_once "Zend/Db/Table.php";
+require_once "Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_DbTableDataSetTest extends PHPUnit_Framework_TestCase
+{
+    public function testAddTableAppendedToTableNames()
+    {
+        $fixtureTable = "foo";
+
+        $table = $this->getMock('Zend_Db_Table', array(), array(), '', false);
+        $table->expects($this->at(0))->method('info')->with('name')->will($this->returnValue($fixtureTable));
+        $table->expects($this->at(1))->method('info')->with('name')->will($this->returnValue($fixtureTable));
+        $table->expects($this->at(2))->method('info')->with('cols')->will($this->returnValue(array()));
+
+        $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
+        $dataSet->addTable($table);
+
+        $this->assertEquals(array($fixtureTable), $dataSet->getTableNames());
+    }
+
+    public function testAddTableCreatesDbTableInstance()
+    {
+        $fixtureTable = "foo";
+
+        $table = $this->getMock('Zend_Db_Table', array(), array(), '', false);
+        $table->expects($this->at(0))->method('info')->with('name')->will($this->returnValue($fixtureTable));
+        $table->expects($this->at(1))->method('info')->with('name')->will($this->returnValue($fixtureTable));
+        $table->expects($this->at(2))->method('info')->with('cols')->will($this->returnValue(array()));
+
+        $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
+        $dataSet->addTable($table);
+
+        $this->assertType('Zend_Test_PHPUnit_Db_DataSet_DbTable', $dataSet->getTable($fixtureTable));
+    }
+
+    public function testGetUnknownTableThrowsException()
+    {
+        $this->setExpectedException('InvalidArgumentException');
+        $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
+        $dataSet->getTable('unknown');
+    }
+}

+ 87 - 0
tests/Zend/Test/PHPUnit/Db/DataSet/DbTableTest.php

@@ -0,0 +1,87 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+require_once "Zend/Test/PHPUnit/Db/DataSet/DbTable.php";
+require_once "Zend/Db/Table.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_DbTableTest extends PHPUnit_Framework_TestCase
+{
+    public function testLoadDataSetDelegatesWhereLimitOrderBy()
+    {
+        $fixtureWhere = "where";
+        $fixtureLimit = "limit";
+        $fixtureOffset = "offset";
+        $fixtureOrderBy = "order";
+
+        $table = $this->getMock('Zend_Db_Table', array(), array(), '', false);
+        $table->expects($this->once())
+              ->method('fetchAll')
+              ->with($fixtureWhere, $fixtureOrderBy, $fixtureLimit, $fixtureOffset)
+              ->will($this->returnValue(array()));
+
+        $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $fixtureWhere, $fixtureOrderBy, $fixtureLimit, $fixtureOffset);
+        $count = $dataSet->getRowCount();
+    }
+
+    public function testGetTableMetadata()
+    {
+        $fixtureTableName = "foo";
+
+        $table = $this->getMock('Zend_Db_Table', array(), array(), '', false);
+        $table->expects($this->at(0))
+              ->method('info')
+              ->with($this->equalTo('name'))
+              ->will($this->returnValue($fixtureTableName));
+        $table->expects($this->at(1))
+              ->method('info')
+              ->with($this->equalTo('cols'))
+              ->will($this->returnValue( array("foo", "bar") ));
+        $table->expects($this->once())
+              ->method('fetchAll')
+              ->will($this->returnValue(array( array("foo" => 1, "bar" => 2) )));
+
+        $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table);
+
+        $this->assertEquals($fixtureTableName, $dataSet->getTableMetaData()->getTableName());
+        $this->assertEquals(array("foo", "bar"), $dataSet->getTableMetaData()->getColumns());
+    }
+
+    public function testLoadDataOnlyCalledOnce()
+    {
+        $table = $this->getMock('Zend_Db_Table', array(), array(), '', false);
+        $table->expects($this->once())
+              ->method('fetchAll')
+              ->will($this->returnValue(array( array("foo" => 1, "bar" => 2) )));
+
+        $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table);
+        $dataSet->getRow(0);
+        $dataSet->getRow(0);
+    }
+}

+ 83 - 0
tests/Zend/Test/PHPUnit/Db/DataSet/QueryDataSetTest.php

@@ -0,0 +1,83 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+require_once "Zend/Test/DbAdapter.php";
+
+require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_DataSet_DataSetTestCase
+ */
+require_once "Zend/Test/PHPUnit/Db/DataSet/DataSetTestCase.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_DataSet_QueryTable
+ */
+require_once "Zend/Test/PHPUnit/Db/DataSet/QueryDataSet.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_QueryDataSetTest extends Zend_Test_PHPUnit_Db_DataSet_DataSetTestCase
+{
+    public function testCreateQueryDataSetWithoutZendDbAdapterThrowsException()
+    {
+        $connectionMock = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection');
+        $this->setExpectedException('Zend_Test_PHPUnit_Db_Exception');
+        $queryDataSet = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet($connectionMock);
+    }
+
+    public function testCreateQueryDataSetWithZendDbAdapter()
+    {
+        $this->decorateConnectionMockWithZendAdapter();
+        $queryDataSet = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet($this->connectionMock);
+    }
+
+    public function testAddTableWithoutQueryParameterCreatesSelectWildcardAll()
+    {
+        $fixtureTableName = "foo";
+
+        $adapterMock = $this->getMock('Zend_Test_DbAdapter');
+        $selectMock = $this->getMock('Zend_Db_Select', array(), array($adapterMock));
+
+        $adapterMock->expects($this->once())
+                    ->method('select')
+                    ->will($this->returnValue($selectMock));
+        $this->decorateConnectionGetConnectionWith($adapterMock);
+
+        $selectMock->expects($this->once())
+                   ->method('from')
+                   ->with($fixtureTableName, Zend_Db_Select::SQL_WILDCARD);
+        $selectMock->expects($this->once())
+                   ->method('__toString')
+                   ->will($this->returnValue('SELECT * FOM foo'));
+
+        $queryDataSet = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet($this->connectionMock);
+        $queryDataSet->addTable('foo');
+    }
+}

+ 110 - 0
tests/Zend/Test/PHPUnit/Db/DataSet/QueryTableTest.php

@@ -0,0 +1,110 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+/**
+ * @see Zend_Test_PHPUnit_Db_DataSet_DataSetTestCase
+ */
+require_once "Zend/Test/PHPUnit/Db/DataSet/DataSetTestCase.php";
+
+require_once "Zend/Db/Statement/Interface.php";
+
+require_once "Zend/Test/DbAdapter.php";
+
+require_once "Zend/Test/DbStatement.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_DataSet_QueryTableTest extends Zend_Test_PHPUnit_Db_DataSet_DataSetTestCase
+{
+    public function testCreateQueryTableWithoutZendDbConnectionThrowsException()
+    {
+        $connectionMock = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection');
+
+        $this->setExpectedException('Zend_Test_PHPUnit_Db_Exception');
+        $queryTable = new Zend_Test_PHPUnit_Db_DataSet_QueryTable("foo", "SELECT * FROM foo", $connectionMock);
+    }
+
+    public function testCreateQueryTableWithZendDbConnection()
+    {
+        $this->decorateConnectionMockWithZendAdapter();
+        $queryTable = new Zend_Test_PHPUnit_Db_DataSet_QueryTable("foo", "SELECT * FROM foo", $this->connectionMock);
+    }
+
+    public function testLoadDataExecutesQueryOnZendAdapter()
+    {
+        $statementMock = new Zend_Test_DbStatement();
+        $statementMock->append(array('foo' => 'bar'));
+        $adapterMock = new Zend_Test_DbAdapter();
+        $adapterMock->appendStatementToStack($statementMock);
+
+        $this->decorateConnectionGetConnectionWith($adapterMock);
+
+        $queryTable = new Zend_Test_PHPUnit_Db_DataSet_QueryTable("foo", "SELECT * FROM foo", $this->connectionMock);
+        $data = $queryTable->getRow(0);
+
+        $this->assertEquals(
+            array("foo" => "bar"), $data
+        );
+    }
+
+    public function testGetRowCountLoadsData()
+    {
+        $statementMock = new Zend_Test_DbStatement();
+        $statementMock->append(array('foo' => 'bar'));
+        $adapterMock = new Zend_Test_DbAdapter();
+        $adapterMock->appendStatementToStack($statementMock);
+
+        $this->decorateConnectionGetConnectionWith($adapterMock);
+
+        $queryTable = new Zend_Test_PHPUnit_Db_DataSet_QueryTable("foo", "SELECT * FROM foo", $this->connectionMock);
+        $count = $queryTable->getRowCount();
+
+        $this->assertEquals(1, $count);
+    }
+
+    public function testDataIsLoadedOnlyOnce()
+    {
+        $fixtureSql = "SELECT * FROM foo";
+
+        $statementMock = new Zend_Test_DbStatement();
+        $statementMock->append(array('foo' => 'bar'));
+        $adapterMock = $this->getMock('Zend_Test_DbAdapter');
+        $adapterMock->expects($this->once())
+                    ->method('query')
+                    ->with($fixtureSql)
+                    ->will($this->returnValue($statementMock));
+
+        $this->decorateConnectionGetConnectionWith($adapterMock);
+
+        $queryTable = new Zend_Test_PHPUnit_Db_DataSet_QueryTable("foo", $fixtureSql, $this->connectionMock);
+        $queryTable->getRowCount();
+        $queryTable->getRowCount();
+        $row = $queryTable->getRow(0);
+    }
+}

+ 141 - 0
tests/Zend/Test/PHPUnit/Db/Integration/AbstractTestCase.php

@@ -0,0 +1,141 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+require_once "Zend/Db/Table/Abstract.php";
+
+require_once "Zend/Db/Table.php";
+
+require_once "Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php";
+
+require_once "PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php";
+
+require_once "Zend/Test/PHPUnit/Db/SimpleTester.php";
+
+require_once "Zend/Test/PHPUnit/Db/DataSet/DbRowset.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+abstract class Zend_Test_PHPUnit_Db_Integration_AbstractTestCase extends PHPUnit_Framework_TestCase
+{
+    /**
+     * @var Zend_Db_Adapter_Abstract
+     */
+    protected $dbAdapter;
+
+    public function testZendDbTableDataSet()
+    {
+        $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
+        $dataSet->addTable($this->createFooTable());
+        $dataSet->addTable($this->createBarTable());
+
+        $this->assertEquals(
+            "foo", $dataSet->getTableMetaData('foo')->getTableName()
+        );
+        $this->assertEquals(
+            "bar", $dataSet->getTableMetaData("bar")->getTableName()
+        );
+
+        $this->assertEquals(array("foo", "bar"), $dataSet->getTableNames());
+    }
+
+    public function testZendDbTableEqualsXmlDataSet()
+    {
+        $fooTable = $this->createFooTable();
+        $fooTable->insert(array("id" => null, "foo" => "foo", "bar" => "bar", "baz" => "baz"));
+        $fooTable->insert(array("id" => null, "foo" => "bar", "bar" => "bar", "baz" => "bar"));
+        $fooTable->insert(array("id" => null, "foo" => "baz", "bar" => "baz", "baz" => "baz"));
+
+        $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
+        $dataSet->addTable($fooTable);
+
+        $xmlDataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(
+            dirname(__FILE__)."/_files/sqliteIntegrationFixture.xml"
+        );
+        $this->assertTrue($xmlDataSet->assertEquals($dataSet));
+    }
+
+    /**
+     * @return Zend_Test_PHPUnit_Db_Connection
+     */
+    public function getConnection()
+    {
+        return new Zend_Test_PHPUnit_Db_Connection($this->dbAdapter, 'foo');
+    }
+
+    public function testSimpleTesterSetupAndRowsetEquals()
+    {
+        $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(
+            dirname(__FILE__)."/_files/sqliteIntegrationFixture.xml"
+        );
+        $fooDataTable = $dataSet->getTable("foo");
+
+        $tester = new Zend_Test_PHPUnit_Db_SimpleTester($this->getConnection());
+        $tester->setUpDatabase($dataSet);
+
+        $fooTable = $this->createFooTable();
+        $rows = $fooTable->fetchAll();
+
+        $this->assertEquals(3, count($rows));
+
+        $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rows);
+        $rowsetTable->assertEquals($fooDataTable);
+    }
+
+    /**
+     * @return Zend_Test_PHPUnit_Db_TableFoo
+     */
+    public function createFooTable()
+    {
+        $table = new Zend_Test_PHPUnit_Db_TableFoo(array('db' => $this->dbAdapter));
+        return $table;
+    }
+
+    /**
+     * @return Zend_Test_PHPUnit_Db_TableBar
+     */
+    public function createBarTable()
+    {
+        $table = new Zend_Test_PHPUnit_Db_TableBar(array('db' => $this->dbAdapter));
+        return $table;
+    }
+}
+
+class Zend_Test_PHPUnit_Db_TableFoo extends Zend_Db_Table_Abstract
+{
+    protected $_name = "foo";
+
+    protected $_primary = "id";
+}
+
+class Zend_Test_PHPUnit_Db_TableBar extends Zend_Db_Table_Abstract
+{
+    protected $_name = "bar";
+
+    protected $_primary = "id";
+}

+ 70 - 0
tests/Zend/Test/PHPUnit/Db/Integration/MysqlIntegrationTest.php

@@ -0,0 +1,70 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+require_once "AbstractTestCase.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Integration_MysqlIntegrationTest extends Zend_Test_PHPUnit_Db_Integration_AbstractTestCase
+{
+    public function setUp()
+    {
+        if (!TESTS_ZEND_DB_ADAPTER_PDO_MYSQL_ENABLED) {
+            $this->markTestSkipped('Database tests are not enabled.');
+            return;
+        }
+
+        if (!extension_loaded('pdo')) {
+            $this->markTestSkipped('PDO is required for this test.');
+            return;
+        }
+
+        if (!in_array('mysql', PDO::getAvailableDrivers())) {
+            $this->markTestSkipped('Mysql is not included in PDO in this PHP installation.');
+            return;
+        }
+
+        $params = array(
+            'host'     => TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME,
+            'username' => TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME,
+            'password' => TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD,
+            'dbname'   => TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE,
+        );
+
+        $this->dbAdapter = Zend_Db::factory('pdo_mysql', $params);
+        $this->dbAdapter->query("DROP TABLE foo");
+        $this->dbAdapter->query("DROP TABLE bar");
+        $this->dbAdapter->query(
+            'CREATE TABLE foo (id INT(10) AUTO_INCREMENT PRIMARY KEY, foo VARCHAR(255), bar VARCHAR(255), baz VARCHAR(255)) AUTO_INCREMENT=1'
+        );
+        $this->dbAdapter->query(
+            'CREATE TABLE bar (id INT(10) AUTO_INCREMENT PRIMARY KEY, foo VARCHAR(255), bar VARCHAR(255), baz VARCHAR(255)) AUTO_INCREMENT=1'
+        );
+    }
+}

+ 54 - 0
tests/Zend/Test/PHPUnit/Db/Integration/SqLiteIntegrationTest.php

@@ -0,0 +1,54 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+require_once "AbstractTestCase.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Integration_SqLiteIntegrationTest extends Zend_Test_PHPUnit_Db_Integration_AbstractTestCase
+{
+    public function setUp()
+    {
+        if (!extension_loaded('pdo')) {
+            $this->markTestSkipped('PDO is required for this test.');
+        }
+
+        if(!in_array('sqlite', PDO::getAvailableDrivers())) {
+            $this->markTestSkipped('SqLite is not included in PDO in this PHP installation.');
+        }
+
+        $this->dbAdapter = Zend_Db::factory('pdo_sqlite', array('dbname' => ':memory:'));
+        $this->dbAdapter->query(
+            'CREATE TABLE "foo" (id INTEGER PRIMARY KEY AUTOINCREMENT, foo VARCHAR, bar VARCHAR, baz VARCHAR)'
+        );
+        $this->dbAdapter->query(
+            'CREATE TABLE "bar" (id INTEGER PRIMARY KEY AUTOINCREMENT, foo VARCHAR, bar VARCHAR, baz VARCHAR)'
+        );
+    }
+}

+ 6 - 0
tests/Zend/Test/PHPUnit/Db/Integration/_files/sqliteIntegrationFixture.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" ?>
+<dataset>
+    <foo id="1" foo="foo" bar="bar" baz="baz" />
+    <foo id="2" foo="bar" bar="bar" baz="bar" />
+    <foo id="3" foo="baz" bar="baz" baz="baz" />
+</dataset>

+ 112 - 0
tests/Zend/Test/PHPUnit/Db/Metadata/GenericTest.php

@@ -0,0 +1,112 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+require_once "Zend/Test/DbAdapter.php";
+require_once "Zend/Test/PHPUnit/Db/Metadata/Generic.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Metadata_GenericTest extends PHPUnit_Framework_TestCase
+{
+    private $adapterMock = null;
+
+    private $metadata = null;
+
+    public function setUp()
+    {
+        $this->adapterMock = $this->getMock('Zend_Test_DbAdapter');
+        $this->metadata = new Zend_Test_PHPUnit_Db_Metadata_Generic($this->adapterMock, "schema");
+    }
+
+    public function testGetSchema()
+    {
+        $this->assertEquals("schema", $this->metadata->getSchema());
+    }
+
+    public function testGetColumnNames()
+    {
+        $fixtureTableName = "foo";
+
+        $this->adapterMock->expects($this->once())
+                          ->method('describeTable')
+                          ->with($fixtureTableName)
+                          ->will($this->returnValue(array("foo" => 1, "bar" => 2)));
+        $data = $this->metadata->getTableColumns($fixtureTableName);
+
+        $this->assertEquals(array("foo", "bar"), $data);
+    }
+
+    public function testGetTableNames()
+    {
+        $this->adapterMock->expects($this->once())
+                          ->method('listTables')
+                          ->will($this->returnValue(array("foo")));
+        $tables = $this->metadata->getTableNames();
+
+        $this->assertEquals(array("foo"), $tables);
+    }
+
+    public function testGetTablePrimaryKey()
+    {
+        $fixtureTableName = "foo";
+
+        $tableMeta = array(
+            array('PRIMARY' => false, 'COLUMN_NAME' => 'foo'),
+            array('PRIMARY' => true, 'COLUMN_NAME' => 'bar'),
+            array('PRIMARY' => true, 'COLUMN_NAME' => 'baz'),
+        );
+
+        $this->adapterMock->expects($this->once())
+                          ->method('describeTable')
+                          ->with($fixtureTableName)
+                          ->will($this->returnValue($tableMeta));
+
+        $primaryKey = $this->metadata->getTablePrimaryKeys($fixtureTableName);
+        $this->assertEquals(array("bar", "baz"), $primaryKey);
+    }
+
+    public function testGetAllowCascading()
+    {
+        $this->assertFalse($this->metadata->allowsCascading());
+    }
+
+    public function testQuoteIdentifierIsDelegated()
+    {
+        $fixtureValue = "foo";
+
+        $this->adapterMock->expects($this->once())
+                          ->method('quoteIdentifier')
+                          ->with($fixtureValue)
+                          ->will($this->returnValue($fixtureValue));
+
+        $actualValue = $this->metadata->quoteSchemaObject($fixtureValue);
+
+        $this->assertEquals($fixtureValue, $actualValue);
+    }
+}

+ 45 - 0
tests/Zend/Test/PHPUnit/Db/Operation/AllTests.php

@@ -0,0 +1,45 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once "InsertTest.php";
+require_once "TruncateTest.php";
+require_once "DeleteAllTest.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Operation_AllTests
+{
+    static public function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('Zend Test PHPUnit Database Operation');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_Operation_InsertTest');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_Operation_TruncateTest');
+        $suite->addTestSuite('Zend_Test_PHPUnit_Db_Operation_DeleteAllTest');
+
+        return $suite;
+    }
+}

+ 89 - 0
tests/Zend/Test/PHPUnit/Db/Operation/DeleteAllTest.php

@@ -0,0 +1,89 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+require_once "Zend/Test/DbAdapter.php";
+
+require_once "Zend/Test/PHPUnit/Db/Operation/DeleteAll.php";
+
+require_once "PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Operation_DeleteAllTest extends PHPUnit_Framework_TestCase
+{
+    private $operation = null;
+
+    public function setUp()
+    {
+        $this->operation = new Zend_Test_PHPUnit_Db_Operation_DeleteAll();
+    }
+
+    public function testDeleteAll()
+    {
+        $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/truncateFixture.xml");
+
+        $testAdapter = $this->getMock('Zend_Test_DbAdapter');
+        $testAdapter->expects($this->at(0))
+                    ->method('delete')
+                    ->with('foo');
+        $testAdapter->expects($this->at(1))
+                    ->method('delete')
+                    ->with('bar');
+
+        $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
+
+        $this->operation->execute($connection, $dataSet);
+    }
+
+    public function testDeleteQueryErrorTransformsException()
+    {
+        $this->setExpectedException('PHPUnit_Extensions_Database_Operation_Exception');
+
+        $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/truncateFixture.xml");
+
+        $testAdapter = $this->getMock('Zend_Test_DbAdapter');
+        $testAdapter->expects($this->any())
+                    ->method('delete')
+                    ->will($this->throwException(new Exception));
+
+        $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
+
+        $this->operation->execute($connection, $dataSet);
+    }
+
+    public function testInvalidConnectionGivenThrowsException()
+    {
+        $this->setExpectedException("Zend_Test_PHPUnit_Db_Exception");
+
+        $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet');
+        $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection');
+
+        $this->operation->execute($connection, $dataSet);
+    }
+}

+ 89 - 0
tests/Zend/Test/PHPUnit/Db/Operation/InsertTest.php

@@ -0,0 +1,89 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+require_once "Zend/Test/DbAdapter.php";
+
+require_once "Zend/Test/PHPUnit/Db/Operation/Insert.php";
+
+require_once "PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Operation_InsertTest extends PHPUnit_Framework_TestCase
+{
+    private $operation = null;
+
+    public function setUp()
+    {
+        $this->operation = new Zend_Test_PHPUnit_Db_Operation_Insert();
+    }
+
+    public function testInsertDataSetUsingAdapterInsert()
+    {
+        $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/insertFixture.xml");
+
+        $testAdapter = $this->getMock('Zend_Test_DbAdapter');
+        $testAdapter->expects($this->at(0))
+                    ->method('insert')
+                    ->with('foo', array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'));
+        $testAdapter->expects($this->at(1))
+                    ->method('insert')
+                    ->with('foo', array('foo' => 'bar', 'bar' => 'bar', 'baz' => 'bar'));
+        $testAdapter->expects($this->at(2))
+                    ->method('insert')
+                    ->with('foo', array('foo' => 'baz', 'bar' => 'baz', 'baz' => 'baz'));
+
+        $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
+
+        $this->operation->execute($connection, $dataSet);
+    }
+
+    public function testInsertExceptionIsTransformed()
+    {
+        $this->setExpectedException('PHPUnit_Extensions_Database_Operation_Exception');
+
+        $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/insertFixture.xml");
+
+        $testAdapter = $this->getMock('Zend_Test_DbAdapter');
+        $testAdapter->expects($this->any())->method('insert')->will($this->throwException(new Exception()));
+
+        $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
+        $this->operation->execute($connection, $dataSet);
+    }
+
+    public function testInvalidConnectionGivenThrowsException()
+    {
+        $this->setExpectedException("Zend_Test_PHPUnit_Db_Exception");
+
+        $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet');
+        $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection');
+        
+        $this->operation->execute($connection, $dataSet);
+    }
+}

+ 93 - 0
tests/Zend/Test/PHPUnit/Db/Operation/TruncateTest.php

@@ -0,0 +1,93 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../../TestHelper.php";
+
+require_once "Zend/Test/DbAdapter.php";
+
+require_once "Zend/Test/PHPUnit/Db/Operation/Truncate.php";
+
+require_once "PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_Operation_TruncateTest extends PHPUnit_Framework_TestCase
+{
+    private $operation = null;
+
+    public function setUp()
+    {
+        $this->operation = new Zend_Test_PHPUnit_Db_Operation_Truncate();
+    }
+
+    public function testTruncateTablesExecutesAdapterQuery()
+    {
+        $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/truncateFixture.xml");
+
+        $testAdapter = $this->getMock('Zend_Test_DbAdapter');
+        $testAdapter->expects($this->at(0))
+                    ->method('quoteIdentifier')
+                    ->with('foo')->will($this->returnValue('foo'));
+        $testAdapter->expects($this->at(1))
+                    ->method('query')
+                    ->with('TRUNCATE foo');
+        $testAdapter->expects($this->at(2))
+                    ->method('quoteIdentifier')
+                    ->with('bar')->will($this->returnValue('bar'));
+        $testAdapter->expects($this->at(3))
+                    ->method('query')
+                    ->with('TRUNCATE bar');
+
+        $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
+
+        $this->operation->execute($connection, $dataSet);
+    }
+
+    public function testTruncateTableInvalidQueryTransformsException()
+    {
+        $this->setExpectedException('PHPUnit_Extensions_Database_Operation_Exception');
+
+        $dataSet = new PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(dirname(__FILE__)."/_files/insertFixture.xml");
+
+        $testAdapter = $this->getMock('Zend_Test_DbAdapter');
+        $testAdapter->expects($this->any())->method('query')->will($this->throwException(new Exception()));
+
+        $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
+
+        $this->operation->execute($connection, $dataSet);
+    }
+
+    public function testInvalidConnectionGivenThrowsException()
+    {
+        $this->setExpectedException("Zend_Test_PHPUnit_Db_Exception");
+
+        $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet');
+        $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection');
+
+        $this->operation->execute($connection, $dataSet);
+    }
+}

+ 6 - 0
tests/Zend/Test/PHPUnit/Db/Operation/_files/insertFixture.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" ?>
+<dataset>
+    <foo foo="foo" bar="bar" baz="baz" />
+    <foo foo="bar" bar="bar" baz="bar" />
+    <foo foo="baz" bar="baz" baz="baz" />
+</dataset>

+ 5 - 0
tests/Zend/Test/PHPUnit/Db/Operation/_files/truncateFixture.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" ?>
+<dataset>
+    <foo />
+    <bar />
+</dataset>

+ 77 - 0
tests/Zend/Test/PHPUnit/Db/SimpleTesterTest.php

@@ -0,0 +1,77 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../TestHelper.php";
+require_once "Zend/Test/PHPUnit/Db/SimpleTester.php";
+require_once "Zend/Test/PHPUnit/Db/Connection.php";
+require_once "Zend/Test/DbAdapter.php";
+require_once "PHPUnit/Extensions/Database/DataSet/IDataSet.php";
+require_once "Zend/Test/PHPUnit/Db/Exception.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_SimpleTesterTest extends PHPUnit_Framework_TestCase
+{
+    public function testGetConnection()
+    {
+        $testAdapter = $this->getMock('Zend_Test_DbAdapter');
+        $testAdapter->expects($this->any())
+                    ->method('delete')
+                    ->will($this->throwException(new Exception));
+
+        $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
+
+        $databaseTester = new Zend_Test_PHPUnit_Db_SimpleTester($connection);
+
+        $this->assertSame($connection, $databaseTester->getConnection());
+    }
+
+    public function testSetupDatabase()
+    {
+        $testAdapter = $this->getMock('Zend_Test_DbAdapter');
+        $testAdapter->expects($this->any())
+                    ->method('delete')
+                    ->will($this->throwException(new Exception));
+
+        $connection = new Zend_Test_PHPUnit_Db_Connection($testAdapter, "schema");
+
+        $databaseTester = new Zend_Test_PHPUnit_Db_SimpleTester($connection);
+
+        $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet');
+        $dataSet->expects($this->any())->method('getIterator')->will($this->returnValue($this->getMock('Iterator')));
+        $databaseTester->setUpDatabase($dataSet);
+    }
+
+    public function testInvalidConnectionGivenThrowsException()
+    {
+        $this->setExpectedException("Zend_Test_PHPUnit_Db_Exception");
+
+        $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection');
+
+        $databaseTester = new Zend_Test_PHPUnit_Db_SimpleTester($connection);
+    }
+}

+ 119 - 0
tests/Zend/Test/PHPUnit/Db/TestCaseTest.php

@@ -0,0 +1,119 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id$
+ */
+
+require_once dirname(__FILE__)."/../../../../TestHelper.php";
+require_once "PHPUnit/Extensions/Database/DataSet/CompositeDataSet.php";
+require_once "Zend/Test/PHPUnit/DatabaseTestCase.php";
+require_once "Zend/Db/Adapter/Abstract.php";
+require_once "Zend/Db/Adapter/Pdo/Sqlite.php";
+require_once "Zend/Db/Table.php";
+require_once "Zend/Db/Table/Rowset.php";
+require_once "Zend/Test/DbAdapter.php";
+
+/**
+ * @category   Zend
+ * @package    Zend_Test
+ * @subpackage UnitTests
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Test_PHPUnit_Db_TestCaseTest extends Zend_Test_PHPUnit_DatabaseTestCase
+{
+    /**
+     * Contains a Database Connection
+     * 
+     * @var PHPUnit_Extensions_Database_DB_IDatabaseConnection
+     */
+    protected $_connectionMock = null;
+
+    /**
+     * Returns the test database connection.
+     *
+     * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
+     */
+    protected function getConnection()
+    {
+        if($this->_connectionMock == null) {
+            $this->_connectionMock = $this->getMock(
+                'Zend_Test_PHPUnit_Db_Connection', array(), array(new Zend_Test_DbAdapter(), "schema")
+            );
+        }
+        return $this->_connectionMock;
+    }
+
+    /**
+     * Returns the test dataset.
+     *
+     * @return PHPUnit_Extensions_Database_DataSet_IDataSet
+     */
+    protected function getDataSet()
+    {
+        return new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
+    }
+
+    public function testDatabaseTesterIsInitialized()
+    {
+        $this->assertTrue($this->databaseTester instanceof PHPUnit_Extensions_Database_ITester);
+    }
+
+    public function testDatabaseTesterNestsDefaultConnection()
+    {
+        $this->assertTrue($this->databaseTester->getConnection() instanceof PHPUnit_Extensions_Database_DB_IDatabaseConnection);
+    }
+
+    public function testCheckZendDbConnectionConvenienceMethodReturnType()
+    {
+        $mock = $this->getMock('Zend_Db_Adapter_Pdo_Sqlite', array('delete'), array(), "Zend_Db_Adapter_Mock", false);
+        $this->assertTrue($this->createZendDbConnection($mock, "test") instanceof Zend_Test_PHPUnit_Db_Connection);
+    }
+
+    public function testCreateDbTableDataSetConvenienceMethodReturnType()
+    {
+        $tableMock = $this->getMock('Zend_Db_Table', array(), array(), "", false);
+        $tableDataSet = $this->createDbTableDataSet(array($tableMock));
+        $this->assertTrue($tableDataSet instanceof Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet);
+    }
+
+    public function testCreateDbTableConvenienceMethodReturnType()
+    {
+        $mock = $this->getMock('Zend_Db_Table', array(), array(), "", false);
+        $table = $this->createDbTable($mock);
+        $this->assertTrue($table instanceof Zend_Test_PHPUnit_Db_DataSet_DbTable);
+    }
+
+    public function testCreateDbRowsetConvenienceMethodReturnType()
+    {
+        $mock = $this->getMock('Zend_Db_Table_Rowset', array(), array(array()));
+        $mock->expects($this->once())->method('toArray')->will($this->returnValue(array("foo" => 1, "bar" => 1)));
+        
+        $rowset = $this->createDbRowset($mock, "fooTable");
+
+        $this->assertTrue($rowset instanceof Zend_Test_PHPUnit_Db_DataSet_DbRowset);
+    }
+
+    public function testGetAdapterConvenienceMethod()
+    {
+        $this->_connectionMock->expects($this->once())
+                              ->method('getConnection');
+        $this->getAdapter();
+    }
+}