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_QueryTable 0025 */ 0026 // require_once "Zend/Test/PHPUnit/Db/DataSet/QueryTable.php"; 0027 0028 /** 0029 * @see Zend_Db_Select 0030 */ 0031 // require_once "Zend/Db/Select.php"; 0032 0033 /** 0034 * Uses several query strings or Zend_Db_Select objects to form a dataset of tables for assertion with other datasets. 0035 * 0036 * @uses PHPUnit_Extensions_Database_DataSet_QueryDataSet 0037 * @category Zend 0038 * @package Zend_Test 0039 * @subpackage PHPUnit 0040 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0041 * @license http://framework.zend.com/license/new-bsd New BSD License 0042 */ 0043 class Zend_Test_PHPUnit_Db_DataSet_QueryDataSet extends PHPUnit_Extensions_Database_DataSet_QueryDataSet 0044 { 0045 /** 0046 * Creates a new dataset using the given database connection. 0047 * 0048 * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection 0049 */ 0050 public function __construct(PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection) 0051 { 0052 if( !($databaseConnection instanceof Zend_Test_PHPUnit_Db_Connection) ) { 0053 // require_once "Zend/Test/PHPUnit/Db/Exception.php"; 0054 throw new Zend_Test_PHPUnit_Db_Exception("Zend_Test_PHPUnit_Db_DataSet_QueryDataSet only works with Zend_Test_PHPUnit_Db_Connection connections-"); 0055 } 0056 $this->databaseConnection = $databaseConnection; 0057 } 0058 0059 /** 0060 * Add a Table dataset representation by specifiying an arbitrary select query. 0061 * 0062 * By default a select * will be done on the given tablename. 0063 * 0064 * @param string $tableName 0065 * @param string|Zend_Db_Select $query 0066 */ 0067 public function addTable($tableName, $query = NULL) 0068 { 0069 if ($query === NULL) { 0070 $query = $this->databaseConnection->getConnection()->select(); 0071 $query->from($tableName, Zend_Db_Select::SQL_WILDCARD); 0072 } 0073 0074 if($query instanceof Zend_Db_Select) { 0075 $query = $query->__toString(); 0076 } 0077 0078 $this->tables[$tableName] = new Zend_Test_PHPUnit_Db_DataSet_QueryTable($tableName, $query, $this->databaseConnection); 0079 } 0080 }