File indexing completed on 2025-02-23 05:32:49
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_DataSet_DbTable 0025 */ 0026 // require_once "Zend/Test/PHPUnit/Db/DataSet/DbTable.php"; 0027 0028 /** 0029 * Aggregate several Zend_Db_Table instances into a dataset. 0030 * 0031 * @uses Zend_Db_Table 0032 * @category Zend 0033 * @package Zend_Test 0034 * @subpackage PHPUnit 0035 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0036 * @license http://framework.zend.com/license/new-bsd New BSD License 0037 */ 0038 class Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet 0039 { 0040 /** 0041 * @var array 0042 */ 0043 protected $tables = array(); 0044 0045 /** 0046 * Add a Table dataset representation by specifiying an arbitrary select query. 0047 * 0048 * By default a select * will be done on the given tablename. 0049 * 0050 * @param Zend_Db_Table_Abstract $table 0051 * @param string $where 0052 * @param string $order 0053 * @param string $count 0054 * @param string $offset 0055 */ 0056 public function addTable(Zend_Db_Table_Abstract $table, $where = null, $order = null, $count = null, $offset = null) 0057 { 0058 $tableName = $table->info('name'); 0059 $this->tables[$tableName] = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $where, $order, $count, $offset); 0060 } 0061 0062 /** 0063 * Creates an iterator over the tables in the data set. If $reverse is 0064 * true a reverse iterator will be returned. 0065 * 0066 * @param bool $reverse 0067 * @return PHPUnit_Extensions_Database_DB_TableIterator 0068 */ 0069 protected function createIterator($reverse = FALSE) 0070 { 0071 return new PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($this->tables, $reverse); 0072 } 0073 0074 /** 0075 * Returns a table object for the given table. 0076 * 0077 * @param string $tableName 0078 * @return PHPUnit_Extensions_Database_DB_Table 0079 */ 0080 public function getTable($tableName) 0081 { 0082 if (!isset($this->tables[$tableName])) { 0083 throw new InvalidArgumentException("$tableName is not a table in the current database."); 0084 } 0085 0086 return $this->tables[$tableName]; 0087 } 0088 0089 /** 0090 * Returns a list of table names for the database 0091 * 0092 * @return Array 0093 */ 0094 public function getTableNames() 0095 { 0096 return array_keys($this->tables); 0097 } 0098 }