|
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: DbRowset.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see Zend_Db_Table_Rowset_Abstract |
|
25 */ |
|
26 require_once "Zend/Db/Table/Rowset/Abstract.php"; |
|
27 |
|
28 /** |
|
29 * @see PHPUnit_Extensions_Database_DataSet_AbstractTable |
|
30 */ |
|
31 require_once "PHPUnit/Extensions/Database/DataSet/AbstractTable.php"; |
|
32 |
|
33 /** |
|
34 * Use a Zend_Db Rowset as a datatable for assertions with other PHPUnit Database extension tables. |
|
35 * |
|
36 * @uses PHPUnit_Extensions_Database_DataSet_AbstractTable |
|
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_DbRowset extends PHPUnit_Extensions_Database_DataSet_AbstractTable |
|
44 { |
|
45 /** |
|
46 * Construct Table object from a Zend_Db_Table_Rowset |
|
47 * |
|
48 * @param Zend_Db_Table_Rowset_Abstract $rowset |
|
49 * @param string $tableName |
|
50 */ |
|
51 public function __construct(Zend_Db_Table_Rowset_Abstract $rowset, $tableName = null) |
|
52 { |
|
53 if($tableName == null) { |
|
54 $table = $rowset->getTable(); |
|
55 if($table !== null) { |
|
56 $tableName = $table->info('name'); |
|
57 } else { |
|
58 require_once "Zend/Test/PHPUnit/Db/Exception.php"; |
|
59 throw new Zend_Test_PHPUnit_Db_Exception( |
|
60 'No table name was given to Rowset Table and table name cannot be infered from the table, '. |
|
61 'because the rowset is disconnected from database.' |
|
62 ); |
|
63 } |
|
64 } |
|
65 |
|
66 $this->data = $rowset->toArray(); |
|
67 |
|
68 $columns = array(); |
|
69 if(isset($this->data[0]) > 0) { |
|
70 $columns = array_keys($this->data[0]); |
|
71 } else if($rowset->getTable() != null) { |
|
72 $columns = $rowset->getTable()->info('cols'); |
|
73 } |
|
74 |
|
75 $this->tableName = $tableName; |
|
76 $this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $columns); |
|
77 } |
|
78 } |