File indexing completed on 2025-01-26 05:29:59

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Test
0017  * @subpackage PHPUnit
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Test_PHPUnit_Db_Operation_Truncate
0025  */
0026 // require_once "Zend/Test/PHPUnit/Db/Operation/Truncate.php";
0027 
0028 /**
0029  * @see Zend_Test_PHPUnit_Db_Operation_Insert
0030  */
0031 // require_once "Zend/Test/PHPUnit/Db/Operation/Insert.php";
0032 
0033 /**
0034  * @see Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet
0035  */
0036 // require_once "Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php";
0037 
0038 /**
0039  * @see Zend_Test_PHPUnit_Db_DataSet_DbTable
0040  */
0041 // require_once "Zend/Test/PHPUnit/Db/DataSet/DbTable.php";
0042 
0043 /**
0044  * @see Zend_Test_PHPUnit_Db_DataSet_DbRowset
0045  */
0046 // require_once "Zend/Test/PHPUnit/Db/DataSet/DbRowset.php";
0047 
0048 /**
0049  * Generic Testcase for Zend Framework related DbUnit Testing with PHPUnit
0050  *
0051  * @uses       PHPUnit_Extensions_Database_TestCase
0052  * @category   Zend
0053  * @package    Zend_Test
0054  * @subpackage PHPUnit
0055  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0056  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0057  */
0058 abstract class Zend_Test_PHPUnit_DatabaseTestCase extends PHPUnit_Extensions_Database_TestCase
0059 {
0060     /**
0061      * Creates a new Zend Database Connection using the given Adapter and database schema name.
0062      *
0063      * @param  Zend_Db_Adapter_Abstract $connection
0064      * @param  string $schema
0065      * @return Zend_Test_PHPUnit_Db_Connection
0066      */
0067     protected function createZendDbConnection(Zend_Db_Adapter_Abstract $connection, $schema)
0068     {
0069         return new Zend_Test_PHPUnit_Db_Connection($connection, $schema);
0070     }
0071 
0072     /**
0073      * Convenience function to get access to the database connection.
0074      *
0075      * @return Zend_Db_Adapter_Abstract
0076      */
0077     protected function getAdapter()
0078     {
0079         return $this->getConnection()->getConnection();
0080     }
0081 
0082     /**
0083      * Returns the database operation executed in test setup.
0084      *
0085      * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation
0086      */
0087     protected function getSetUpOperation()
0088     {
0089         return new PHPUnit_Extensions_Database_Operation_Composite(array(
0090             new Zend_Test_PHPUnit_Db_Operation_Truncate(),
0091             new Zend_Test_PHPUnit_Db_Operation_Insert(),
0092         ));
0093     }
0094 
0095     /**
0096      * Returns the database operation executed in test cleanup.
0097      *
0098      * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation
0099      */
0100     protected function getTearDownOperation()
0101     {
0102         return PHPUnit_Extensions_Database_Operation_Factory::NONE();
0103     }
0104 
0105     /**
0106      * Create a dataset based on multiple Zend_Db_Table instances
0107      *
0108      * @param  array $tables
0109      * @return Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet
0110      */
0111     protected function createDbTableDataSet(array $tables=array())
0112     {
0113         $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet();
0114         foreach($tables AS $table) {
0115             $dataSet->addTable($table);
0116         }
0117         return $dataSet;
0118     }
0119 
0120     /**
0121      * Create a table based on one Zend_Db_Table instance
0122      *
0123      * @param Zend_Db_Table_Abstract $table
0124      * @param string $where
0125      * @param string $order
0126      * @param string $count
0127      * @param string $offset
0128      * @return Zend_Test_PHPUnit_Db_DataSet_DbTable
0129      */
0130     protected function createDbTable(Zend_Db_Table_Abstract $table, $where=null, $order=null, $count=null, $offset=null)
0131     {
0132         return new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $where, $order, $count, $offset);
0133     }
0134 
0135     /**
0136      * Create a data table based on a Zend_Db_Table_Rowset instance
0137      *
0138      * @param  Zend_Db_Table_Rowset_Abstract $rowset
0139      * @param  string
0140      * @return Zend_Test_PHPUnit_Db_DataSet_DbRowset
0141      */
0142     protected function createDbRowset(Zend_Db_Table_Rowset_Abstract $rowset, $tableName = null)
0143     {
0144         return new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset, $tableName);
0145     }
0146 }