web/lib/Zend/Test/PHPUnit/Db/DataSet/DbTable.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: DbTable.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * @see PHPUnit_Extensions_Database_DataSet_QueryTable
       
    25  */
       
    26 require_once "PHPUnit/Extensions/Database/DataSet/QueryTable.php";
       
    27 
       
    28 /**
       
    29  * @see Zend_Db_Table_Abstract
       
    30  */
       
    31 require_once "Zend/Db/Table/Abstract.php";
       
    32 
       
    33 /**
       
    34  * Use a Zend_Db_Table for assertions with other PHPUnit Database Extension table types.
       
    35  *
       
    36  * @uses       PHPUnit_Extensions_Database_DataSet_QueryTable
       
    37  * @category   Zend
       
    38  * @package    Zend_Test
       
    39  * @subpackage PHPUnit
       
    40  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    41  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    42  */
       
    43 class Zend_Test_PHPUnit_Db_DataSet_DbTable extends PHPUnit_Extensions_Database_DataSet_QueryTable
       
    44 {
       
    45     /**
       
    46      * Zend_Db_Table object
       
    47      *
       
    48      * @var Zend_Db_Table_Abstract
       
    49      */
       
    50     protected $_table = null;
       
    51 
       
    52     /**
       
    53      * @var array
       
    54      */
       
    55     protected $_columns = array();
       
    56 
       
    57     /**
       
    58      * @var string
       
    59      */
       
    60     protected $_where = null;
       
    61 
       
    62     /**
       
    63      * @var string
       
    64      */
       
    65     protected $_orderBy = null;
       
    66 
       
    67     /**
       
    68      * @var string
       
    69      */
       
    70     protected $_count = null;
       
    71 
       
    72     /**
       
    73      * @var int
       
    74      */
       
    75     protected $_offset = null;
       
    76 
       
    77     /**
       
    78      * Construct Dataset Table from Zend_Db_Table object
       
    79      *
       
    80      * @param Zend_Db_Table_Abstract        $table
       
    81      * @param string|Zend_Db_Select|null    $where
       
    82      * @param string|null                   $order
       
    83      * @param int                           $count
       
    84      * @param int                           $offset
       
    85      */
       
    86     public function __construct(Zend_Db_Table_Abstract $table, $where=null, $order=null, $count=null, $offset=null)
       
    87     {
       
    88         $this->tableName = $table->info('name');
       
    89         $this->_columns = $table->info('cols');
       
    90 
       
    91         $this->_table = $table;
       
    92         $this->_where = $where;
       
    93         $this->_order = $order;
       
    94         $this->_count = $count;
       
    95         $this->_offset = $offset;
       
    96     }
       
    97 
       
    98     /**
       
    99      * Lazy load data via table fetchAll() method.
       
   100      *
       
   101      * @return void
       
   102      */
       
   103     protected function loadData()
       
   104     {
       
   105         if ($this->data === null) {
       
   106             $this->data = $this->_table->fetchAll(
       
   107                 $this->_where, $this->_order, $this->_count, $this->_offset
       
   108             );
       
   109             if($this->data instanceof Zend_Db_Table_Rowset_Abstract) {
       
   110                 $this->data = $this->data->toArray();
       
   111             }
       
   112         }
       
   113     }
       
   114 
       
   115     /**
       
   116      * Create Table Metadata object
       
   117      */
       
   118     protected function createTableMetaData()
       
   119     {
       
   120         if ($this->tableMetaData === NULL) {
       
   121             $this->loadData();
       
   122             $this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $this->_columns);
       
   123         }
       
   124     }
       
   125 }