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  * Represent a PHPUnit Database Extension table with Queries using a Zend_Db adapter for assertion against other tables.
0025  *
0026  * @uses       PHPUnit_Extensions_Database_DataSet_QueryTable
0027  * @category   Zend
0028  * @package    Zend_Test
0029  * @subpackage PHPUnit
0030  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0031  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0032  */
0033 class Zend_Test_PHPUnit_Db_DataSet_QueryTable extends PHPUnit_Extensions_Database_DataSet_QueryTable
0034 {
0035     /**
0036      * Creates a new database query table object.
0037      *
0038      * @param string                                             $tableName
0039      * @param string                                             $query
0040      * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection
0041      * @throws Zend_Test_PHPUnit_Db_Exception
0042      */
0043     public function __construct($tableName, $query, PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection)
0044     {
0045         if( !($databaseConnection instanceof Zend_Test_PHPUnit_Db_Connection) ) {
0046             // require_once "Zend/Test/PHPUnit/Db/Exception.php";
0047             throw new Zend_Test_PHPUnit_Db_Exception("Zend_Test_PHPUnit_Db_DataSet_QueryTable only works with Zend_Test_PHPUnit_Db_Connection connections-");
0048         }
0049         parent::__construct($tableName, $query, $databaseConnection);
0050     }
0051 
0052     /**
0053      * Load data from the database.
0054      *
0055      * @return void
0056      */
0057     protected function loadData()
0058     {
0059         if($this->data === null) {
0060             $stmt = $this->databaseConnection->getConnection()->query($this->query);
0061             $this->data = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
0062         }
0063     }
0064 
0065     /**
0066      * Create Table Metadata
0067      */
0068     protected function createTableMetaData()
0069     {
0070         if ($this->tableMetaData === NULL)
0071         {
0072             $this->loadData();
0073             $keys = array();
0074             if(count($this->data) > 0) {
0075                 $keys = array_keys($this->data[0]);
0076             }
0077             $this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData(
0078                 $this->tableName, $keys
0079             );
0080         }
0081     }
0082 }