web/Zend/Test/PHPUnit/DatabaseTestCase.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Test
       
    17  * @subpackage PHPUnit
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: DatabaseTestCase.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see PHPUnit_Extensions_Database_TestCase
       
    25  */
       
    26 require_once "PHPUnit/Extensions/Database/TestCase.php";
       
    27 
       
    28 /**
       
    29  * @see Zend_Test_PHPUnit_Db_Operation_Truncate
       
    30  */
       
    31 require_once "Zend/Test/PHPUnit/Db/Operation/Truncate.php";
       
    32 
       
    33 /**
       
    34  * @see Zend_Test_PHPUnit_Db_Operation_Insert
       
    35  */
       
    36 require_once "Zend/Test/PHPUnit/Db/Operation/Insert.php";
       
    37 
       
    38 /**
       
    39  * @see Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet
       
    40  */
       
    41 require_once "Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php";
       
    42 
       
    43 /**
       
    44  * @see Zend_Test_PHPUnit_Db_DataSet_DbTable
       
    45  */
       
    46 require_once "Zend/Test/PHPUnit/Db/DataSet/DbTable.php";
       
    47 
       
    48 /**
       
    49  * @see Zend_Test_PHPUnit_Db_DataSet_DbRowset
       
    50  */
       
    51 require_once "Zend/Test/PHPUnit/Db/DataSet/DbRowset.php";
       
    52 
       
    53 /**
       
    54  * Generic Testcase for Zend Framework related DbUnit Testing with PHPUnit
       
    55  *
       
    56  * @uses       PHPUnit_Extensions_Database_TestCase
       
    57  * @category   Zend
       
    58  * @package    Zend_Test
       
    59  * @subpackage PHPUnit
       
    60  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    61  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    62  */
       
    63 abstract class Zend_Test_PHPUnit_DatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
       
    64 {
       
    65     /**
       
    66      * Creates a new Zend Database Connection using the given Adapter and database schema name.
       
    67      *
       
    68      * @param  Zend_Db_Adapter_Abstract $connection
       
    69      * @param  string $schema
       
    70      * @return Zend_Test_PHPUnit_Db_Connection
       
    71      */
       
    72     protected function createZendDbConnection(Zend_Db_Adapter_Abstract $connection, $schema)
       
    73     {
       
    74         return new Zend_Test_PHPUnit_Db_Connection($connection, $schema);
       
    75     }
       
    76 
       
    77     /**
       
    78      * Convenience function to get access to the database connection.
       
    79      *
       
    80      * @return Zend_Db_Adapter_Abstract
       
    81      */
       
    82     protected function getAdapter()
       
    83     {
       
    84         return $this->getConnection()->getConnection();
       
    85     }
       
    86 
       
    87     /**
       
    88      * Returns the database operation executed in test setup.
       
    89      *
       
    90      * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation
       
    91      */
       
    92     protected function getSetUpOperation()
       
    93     {
       
    94         return new PHPUnit_Extensions_Database_Operation_Composite(array(
       
    95             new Zend_Test_PHPUnit_Db_Operation_Truncate(),
       
    96             new Zend_Test_PHPUnit_Db_Operation_Insert(),
       
    97         ));
       
    98     }
       
    99 
       
   100     /**
       
   101      * Returns the database operation executed in test cleanup.
       
   102      *
       
   103      * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation
       
   104      */
       
   105     protected function getTearDownOperation()
       
   106     {
       
   107         return PHPUnit_Extensions_Database_Operation_Factory::NONE();
       
   108     }
       
   109 
       
   110     /**
       
   111      * Create a dataset based on multiple Zend_Db_Table instances
       
   112      *
       
   113      * @param  array $tables
       
   114      * @return Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet
       
   115      */
       
   116     protected function createDbTableDataSet(array $tables=array())
       
   117     {
       
   118         $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
       
   119         foreach($tables AS $table) {
       
   120             $dataSet->addTable($table);
       
   121         }
       
   122         return $dataSet;
       
   123     }
       
   124 
       
   125     /**
       
   126      * Create a table based on one Zend_Db_Table instance
       
   127      *
       
   128      * @param Zend_Db_Table_Abstract $table
       
   129      * @param string $where
       
   130      * @param string $order
       
   131      * @param string $count
       
   132      * @param string $offset
       
   133      * @return Zend_Test_PHPUnit_Db_DataSet_DbTable
       
   134      */
       
   135     protected function createDbTable(Zend_Db_Table_Abstract $table, $where=null, $order=null, $count=null, $offset=null)
       
   136     {
       
   137         return new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $where, $order, $count, $offset);
       
   138     }
       
   139 
       
   140     /**
       
   141      * Create a data table based on a Zend_Db_Table_Rowset instance
       
   142      *
       
   143      * @param  Zend_Db_Table_Rowset_Abstract $rowset
       
   144      * @param  string
       
   145      * @return Zend_Test_PHPUnit_Db_DataSet_DbRowset
       
   146      */
       
   147     protected function createDbRowset(Zend_Db_Table_Rowset_Abstract $rowset, $tableName = null)
       
   148     {
       
   149         return new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset, $tableName);
       
   150     }
       
   151 }