File indexing completed on 2024-12-29 05:28:07
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_Db_Adapter_Abstract 0025 */ 0026 // require_once "Zend/Db/Adapter/Abstract.php"; 0027 0028 /** 0029 * Generic Metadata accessor for the Zend_Db adapters 0030 * 0031 * @uses PHPUnit_Extensions_Database_DB_IMetaData 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_Metadata_Generic implements PHPUnit_Extensions_Database_DB_IMetaData 0039 { 0040 /** 0041 * Zend_Db Connection 0042 * 0043 * @var Zend_Db_Adapter_Abstract 0044 */ 0045 protected $_connection; 0046 0047 /** 0048 * Schemaname 0049 * 0050 * @var string 0051 */ 0052 protected $_schema; 0053 0054 /** 0055 * Cached Table metadata 0056 * 0057 * @var array 0058 */ 0059 protected $_tableMetadata = array(); 0060 0061 /** 0062 * Creates a new database meta data object using the given pdo connection 0063 * and schema name. 0064 * 0065 * @param Zend_Db_Adapter_Abstract $db 0066 * @param string $schema 0067 */ 0068 public final function __construct(Zend_Db_Adapter_Abstract $db, $schema) 0069 { 0070 $this->_connection = $db; 0071 $this->_schema = $schema; 0072 } 0073 0074 /** 0075 * List Tables 0076 * 0077 * @return array 0078 */ 0079 public function getTableNames() 0080 { 0081 return $this->_connection->listTables(); 0082 } 0083 0084 /** 0085 * Get Table information 0086 * 0087 * @param string $tableName 0088 * @return array 0089 */ 0090 protected function getTableDescription($tableName) 0091 { 0092 if(!isset($this->_tableMetadata[$tableName])) { 0093 $this->_tableMetadata[$tableName] = $this->_connection->describeTable($tableName); 0094 } 0095 return $this->_tableMetadata[$tableName]; 0096 } 0097 0098 /** 0099 * Returns an array containing the names of all the columns in the 0100 * $tableName table, 0101 * 0102 * @param string $tableName 0103 * @return array 0104 */ 0105 public function getTableColumns($tableName) 0106 { 0107 $tableMeta = $this->getTableDescription($tableName); 0108 $columns = array_keys($tableMeta); 0109 return $columns; 0110 } 0111 0112 /** 0113 * Returns an array containing the names of all the primary key columns in 0114 * the $tableName table. 0115 * 0116 * @param string $tableName 0117 * @return array 0118 */ 0119 public function getTablePrimaryKeys($tableName) 0120 { 0121 $tableMeta = $this->getTableDescription($tableName); 0122 0123 $primaryColumnNames = array(); 0124 foreach($tableMeta AS $column) { 0125 if($column['PRIMARY'] == true) { 0126 $primaryColumnNames[] = $column['COLUMN_NAME']; 0127 } 0128 } 0129 return $primaryColumnNames; 0130 } 0131 0132 /** 0133 * Returns the name of the default schema. 0134 * 0135 * @return string 0136 */ 0137 public function getSchema() 0138 { 0139 return $this->_schema; 0140 } 0141 0142 /** 0143 * Returns a quoted schema object. (table name, column name, etc) 0144 * 0145 * @param string $object 0146 * @return string 0147 */ 0148 public function quoteSchemaObject($object) 0149 { 0150 return $this->_connection->quoteIdentifier($object); 0151 } 0152 0153 /** 0154 * Returns true if the rdbms allows cascading 0155 * 0156 * @return bool 0157 */ 0158 public function allowsCascading() 0159 { 0160 return false; 0161 } 0162 0163 /** 0164 * Disables primary keys if rdbms does not allow setting them otherwise 0165 * 0166 * @param string $tableName 0167 */ 0168 public function disablePrimaryKeys($tableName) 0169 { 0170 // Implemented only to match new DBUnit interface 0171 } 0172 0173 /** 0174 * Reenables primary keys after they have been disabled 0175 * 0176 * @param string $tableName 0177 */ 0178 public function enablePrimaryKeys($tableName) 0179 { 0180 // Implemented only to match new DBUnit interface 0181 } 0182 }