web/enmi/Zend/Test/PHPUnit/Db/DataSet/DbTableDataSet.php
changeset 19 1c2f13fd785c
parent 0 4eba9c11703f
equal deleted inserted replaced
18:bd595ad770fc 19:1c2f13fd785c
       
     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: DbTableDataSet.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 require_once "PHPUnit/Extensions/Database/DataSet/QueryDataSet.php";
       
    24 
       
    25 require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
       
    26 
       
    27 /**
       
    28  * @see Zend_Test_PHPUnit_Db_DataSet_DbTable
       
    29  */
       
    30 require_once "Zend/Test/PHPUnit/Db/DataSet/DbTable.php";
       
    31 
       
    32 /**
       
    33  * Aggregate several Zend_Db_Table instances into a dataset.
       
    34  *
       
    35  * @uses       Zend_Db_Table
       
    36  * @category   Zend
       
    37  * @package    Zend_Test
       
    38  * @subpackage PHPUnit
       
    39  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    40  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    41  */
       
    42 class Zend_Test_PHPUnit_Db_DataSet_DbTableDataSet extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet
       
    43 {
       
    44     /**
       
    45      * @var array
       
    46      */
       
    47     protected $tables = array();
       
    48 
       
    49     /**
       
    50      * Add a Table dataset representation by specifiying an arbitrary select query.
       
    51      *
       
    52      * By default a select * will be done on the given tablename.
       
    53      *
       
    54      * @param Zend_Db_Table_Abstract $table
       
    55      * @param string|Zend_Db_Select $query
       
    56      * @param string $where
       
    57      * @param string $order
       
    58      * @param string $count
       
    59      * @param string $offset
       
    60      */
       
    61     public function addTable(Zend_Db_Table_Abstract $table, $where = null, $order = null, $count = null, $offset = null)
       
    62     {
       
    63         $tableName = $table->info('name');
       
    64         $this->tables[$tableName] = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $where, $order, $count, $offset);
       
    65     }
       
    66 
       
    67     /**
       
    68      * Creates an iterator over the tables in the data set. If $reverse is
       
    69      * true a reverse iterator will be returned.
       
    70      *
       
    71      * @param bool $reverse
       
    72      * @return PHPUnit_Extensions_Database_DB_TableIterator
       
    73      */
       
    74     protected function createIterator($reverse = FALSE)
       
    75     {
       
    76         return new PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($this->tables, $reverse);
       
    77     }
       
    78 
       
    79     /**
       
    80      * Returns a table object for the given table.
       
    81      *
       
    82      * @param string $tableName
       
    83      * @return PHPUnit_Extensions_Database_DB_Table
       
    84      */
       
    85     public function getTable($tableName)
       
    86     {
       
    87         if (!isset($this->tables[$tableName])) {
       
    88             throw new InvalidArgumentException("$tableName is not a table in the current database.");
       
    89         }
       
    90 
       
    91         return $this->tables[$tableName];
       
    92     }
       
    93 
       
    94     /**
       
    95      * Returns a list of table names for the database
       
    96      *
       
    97      * @return Array
       
    98      */
       
    99     public function getTableNames()
       
   100     {
       
   101         return array_keys($this->tables);
       
   102     }
       
   103 }