PageRenderTime 86ms CodeModel.GetById 67ms app.highlight 2ms RepoModel.GetById 6ms app.codeStats 0ms

/zf/library/Zend/Test/PHPUnit/Db/Connection.php

http://github.com/eryx/php-framework-benchmark
PHP | 149 lines | 42 code | 13 blank | 94 comment | 1 complexity | 3271a25e15e3e56ebdd1f0234d80444f MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, Apache-2.0, LGPL-2.1, LGPL-3.0, BSD-2-Clause
  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-2011 Zend Technologies USA Inc. (http://www.zend.com)
 19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 20 * @version    $Id: Connection.php 23775 2011-03-01 17:25:24Z ralph $
 21 */
 22
 23/**
 24 * @see PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
 25 */
 26require_once "PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php";
 27
 28/**
 29 * @see Zend_Test_PHPUnit_Db_DataSet_QueryTable
 30 */
 31require_once "Zend/Test/PHPUnit/Db/DataSet/QueryTable.php";
 32
 33/**
 34 * @see Zend_Test_PHPUnit_Db_Metadata_Generic
 35 */
 36require_once "Zend/Test/PHPUnit/Db/Metadata/Generic.php";
 37
 38/**
 39 * Generic Abstraction of Zend_Db Connections in the PHPUnit Database Extension context.
 40 *
 41 * @uses       Zend_Db_Adapter_Abstract
 42 * @uses       PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
 43 * @category   Zend
 44 * @package    Zend_Test
 45 * @subpackage PHPUnit
 46 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 47 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 48 */
 49class Zend_Test_PHPUnit_Db_Connection extends PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
 50{
 51    /**
 52     * Zend_Db_Adapter_Abstract
 53     *
 54     * @var Zend_Db_Adapter_Abstract
 55     */
 56    protected $_connection;
 57
 58    /**
 59     * Database Schema
 60     *
 61     * @var string $db
 62     */
 63    protected $_schema;
 64
 65    /**
 66     * Metadata
 67     *
 68     * @param PHPUnit_Extensions_Database_DB_IMetaData $db
 69     */
 70    protected $_metaData;
 71
 72    /**
 73     * Construct Connection based on Zend_Db_Adapter_Abstract
 74     *
 75     * @param Zend_Db_Adapter_Abstract $db
 76     * @param string $schema
 77     */
 78    public function __construct(Zend_Db_Adapter_Abstract $db, $schema)
 79    {
 80        $this->_connection = $db;
 81        $this->_schema = $schema;
 82    }
 83
 84    /**
 85     * Close this connection.
 86     *
 87     * @return void
 88     */
 89    public function close()
 90    {
 91        $this->_connection->closeConnection();
 92    }
 93
 94    /**
 95     * Creates a table with the result of the specified SQL statement.
 96     *
 97     * @param string $resultName
 98     * @param string $sql
 99     * @return PHPUnit_Extensions_Database_DataSet_ITable
100     */
101    public function createQueryTable($resultName, $sql)
102    {
103        return new Zend_Test_PHPUnit_Db_DataSet_QueryTable($resultName, $sql, $this);
104    }
105
106    /**
107     * Returns a Zend_Db Connection
108     *
109     * @return Zend_Db_Adapter_Abstract
110     */
111    public function getConnection()
112    {
113        return $this->_connection;
114    }
115
116    /**
117     * Returns a database metadata object that can be used to retrieve table
118     * meta data from the database.
119     *
120     * @return PHPUnit_Extensions_Database_DB_IMetaData
121     */
122    public function getMetaData()
123    {
124        if($this->_metaData === null) {
125            $this->_metaData = new Zend_Test_PHPUnit_Db_Metadata_Generic($this->getConnection(), $this->getSchema());
126        }
127        return $this->_metaData;
128    }
129
130    /**
131     * Returns the schema for the connection.
132     *
133     * @return string
134     */
135    public function getSchema()
136    {
137        return $this->_schema;
138    }
139
140    /**
141     * Returns the command used to truncate a table.
142     *
143     * @return string
144     */
145    public function getTruncateCommand()
146    {
147        return "DELETE";
148    }
149}