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_Test_PHPUnit_Db_DataSet_QueryTable
0025  */
0026 // require_once "Zend/Test/PHPUnit/Db/DataSet/QueryTable.php";
0027 
0028 /**
0029  * @see Zend_Test_PHPUnit_Db_Metadata_Generic
0030  */
0031 // require_once "Zend/Test/PHPUnit/Db/Metadata/Generic.php";
0032 
0033 /**
0034  * Generic Abstraction of Zend_Db Connections in the PHPUnit Database Extension context.
0035  *
0036  * @uses       Zend_Db_Adapter_Abstract
0037  * @uses       PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
0038  * @category   Zend
0039  * @package    Zend_Test
0040  * @subpackage PHPUnit
0041  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0042  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0043  */
0044 class Zend_Test_PHPUnit_Db_Connection extends PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
0045 {
0046     /**
0047      * Zend_Db_Adapter_Abstract
0048      *
0049      * @var Zend_Db_Adapter_Abstract
0050      */
0051     protected $_connection;
0052 
0053     /**
0054      * Database Schema
0055      *
0056      * @var string $db
0057      */
0058     protected $_schema;
0059 
0060     /**
0061      * Metadata
0062      *
0063      * @param PHPUnit_Extensions_Database_DB_IMetaData $db
0064      */
0065     protected $_metaData;
0066 
0067     /**
0068      * Construct Connection based on Zend_Db_Adapter_Abstract
0069      *
0070      * @param Zend_Db_Adapter_Abstract $db
0071      * @param string $schema
0072      */
0073     public function __construct(Zend_Db_Adapter_Abstract $db, $schema)
0074     {
0075         $this->_connection = $db;
0076         $this->_schema = $schema;
0077     }
0078 
0079     /**
0080      * Close this connection.
0081      *
0082      * @return void
0083      */
0084     public function close()
0085     {
0086         $this->_connection->closeConnection();
0087     }
0088 
0089     /**
0090      * Creates a table with the result of the specified SQL statement.
0091      *
0092      * @param string $resultName
0093      * @param string $sql
0094      * @return PHPUnit_Extensions_Database_DataSet_ITable
0095      */
0096     public function createQueryTable($resultName, $sql)
0097     {
0098         return new Zend_Test_PHPUnit_Db_DataSet_QueryTable($resultName, $sql, $this);
0099     }
0100 
0101     /**
0102      * Returns a Zend_Db Connection
0103      *
0104      * @return Zend_Db_Adapter_Abstract
0105      */
0106     public function getConnection()
0107     {
0108         return $this->_connection;
0109     }
0110 
0111     /**
0112      * Returns a database metadata object that can be used to retrieve table
0113      * meta data from the database.
0114      *
0115      * @return PHPUnit_Extensions_Database_DB_IMetaData
0116      */
0117     public function getMetaData()
0118     {
0119         if($this->_metaData === null) {
0120             $this->_metaData = new Zend_Test_PHPUnit_Db_Metadata_Generic($this->getConnection(), $this->getSchema());
0121         }
0122         return $this->_metaData;
0123     }
0124 
0125     /**
0126      * Returns the schema for the connection.
0127      *
0128      * @return string
0129      */
0130     public function getSchema()
0131     {
0132         return $this->_schema;
0133     }
0134 
0135     /**
0136      * Returns the command used to truncate a table.
0137      *
0138      * @return string
0139      */
0140     public function getTruncateCommand()
0141     {
0142         return "DELETE";
0143     }
0144 }