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_Db_Table_Rowset_Abstract
0025  */
0026 // require_once "Zend/Db/Table/Rowset/Abstract.php";
0027 
0028 /**
0029  * Use a Zend_Db Rowset as a datatable for assertions with other PHPUnit Database extension tables.
0030  *
0031  * @uses       PHPUnit_Extensions_Database_DataSet_AbstractTable
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_DataSet_DbRowset extends PHPUnit_Extensions_Database_DataSet_AbstractTable
0039 {
0040     /**
0041      * Construct Table object from a Zend_Db_Table_Rowset
0042      *
0043      * @param Zend_Db_Table_Rowset_Abstract $rowset
0044      * @param string $tableName
0045      */
0046     public function __construct(Zend_Db_Table_Rowset_Abstract $rowset, $tableName = null)
0047     {
0048         if($tableName == null) {
0049             $table = $rowset->getTable();
0050             if($table !== null) {
0051                 $tableName = $table->info('name');
0052             } else {
0053                 // require_once "Zend/Test/PHPUnit/Db/Exception.php";
0054                 throw new Zend_Test_PHPUnit_Db_Exception(
0055                     'No table name was given to Rowset Table and table name cannot be infered from the table, '.
0056                     'because the rowset is disconnected from database.'
0057                 );
0058             }
0059         }
0060 
0061         $this->data = $rowset->toArray();
0062 
0063         $columns = array();
0064         if(isset($this->data[0]) > 0) {
0065             $columns = array_keys($this->data[0]);
0066         } else if($rowset->getTable() != null) {
0067             $columns = $rowset->getTable()->info('cols');
0068         }
0069 
0070         $this->tableName = $tableName;
0071         $this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $columns);
0072     }
0073 }