|
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: QueryTable.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 PHPUnit_Extensions_Database_DB_IDatabaseConnection |
|
30 */ |
|
31 require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php"; |
|
32 |
|
33 /** |
|
34 * Represent a PHPUnit Database Extension table with Queries using a Zend_Db adapter for assertion against other tables. |
|
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_QueryTable extends PHPUnit_Extensions_Database_DataSet_QueryTable |
|
44 { |
|
45 /** |
|
46 * Creates a new database query table object. |
|
47 * |
|
48 * @param string $table_name |
|
49 * @param string $query |
|
50 * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection |
|
51 */ |
|
52 public function __construct($tableName, $query, PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection) |
|
53 { |
|
54 if( !($databaseConnection instanceof Zend_Test_PHPUnit_Db_Connection) ) { |
|
55 require_once "Zend/Test/PHPUnit/Db/Exception.php"; |
|
56 throw new Zend_Test_PHPUnit_Db_Exception("Zend_Test_PHPUnit_Db_DataSet_QueryTable only works with Zend_Test_PHPUnit_Db_Connection connections-"); |
|
57 } |
|
58 parent::__construct($tableName, $query, $databaseConnection); |
|
59 } |
|
60 |
|
61 /** |
|
62 * Load data from the database. |
|
63 * |
|
64 * @return void |
|
65 */ |
|
66 protected function loadData() |
|
67 { |
|
68 if($this->data === null) { |
|
69 $stmt = $this->databaseConnection->getConnection()->query($this->query); |
|
70 $this->data = $stmt->fetchAll(Zend_Db::FETCH_ASSOC); |
|
71 } |
|
72 } |
|
73 |
|
74 /** |
|
75 * Create Table Metadata |
|
76 */ |
|
77 protected function createTableMetaData() |
|
78 { |
|
79 if ($this->tableMetaData === NULL) |
|
80 { |
|
81 $this->loadData(); |
|
82 $keys = array(); |
|
83 if(count($this->data) > 0) { |
|
84 $keys = array_keys($this->data[0]); |
|
85 } |
|
86 $this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData( |
|
87 $this->tableName, $keys |
|
88 ); |
|
89 } |
|
90 } |
|
91 } |