|
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: QueryDataSet.php 20096 2010-01-06 02:05:09Z bkarwin $ |
|
21 */ |
|
22 |
|
23 /** |
|
24 * @see PHPUnit_Extensions_Database_DataSet_QueryDataSet |
|
25 */ |
|
26 require_once "PHPUnit/Extensions/Database/DataSet/QueryDataSet.php"; |
|
27 |
|
28 /** |
|
29 * @see PHPUnit_Extensions_Database_DB_IDatabaseConnection |
|
30 */ |
|
31 require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php"; |
|
32 |
|
33 /** |
|
34 * @see Zend_Test_PHPUnit_Db_DataSet_QueryTable |
|
35 */ |
|
36 require_once "Zend/Test/PHPUnit/Db/DataSet/QueryTable.php"; |
|
37 |
|
38 /** |
|
39 * @see Zend_Db_Select |
|
40 */ |
|
41 require_once "Zend/Db/Select.php"; |
|
42 |
|
43 /** |
|
44 * Uses several query strings or Zend_Db_Select objects to form a dataset of tables for assertion with other datasets. |
|
45 * |
|
46 * @uses PHPUnit_Extensions_Database_DataSet_QueryDataSet |
|
47 * @category Zend |
|
48 * @package Zend_Test |
|
49 * @subpackage PHPUnit |
|
50 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
51 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
52 */ |
|
53 class Zend_Test_PHPUnit_Db_DataSet_QueryDataSet extends PHPUnit_Extensions_Database_DataSet_QueryDataSet |
|
54 { |
|
55 /** |
|
56 * Creates a new dataset using the given database connection. |
|
57 * |
|
58 * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection |
|
59 */ |
|
60 public function __construct(PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection) |
|
61 { |
|
62 if( !($databaseConnection instanceof Zend_Test_PHPUnit_Db_Connection) ) { |
|
63 require_once "Zend/Test/PHPUnit/Db/Exception.php"; |
|
64 throw new Zend_Test_PHPUnit_Db_Exception("Zend_Test_PHPUnit_Db_DataSet_QueryDataSet only works with Zend_Test_PHPUnit_Db_Connection connections-"); |
|
65 } |
|
66 $this->databaseConnection = $databaseConnection; |
|
67 } |
|
68 |
|
69 /** |
|
70 * Add a Table dataset representation by specifiying an arbitrary select query. |
|
71 * |
|
72 * By default a select * will be done on the given tablename. |
|
73 * |
|
74 * @param string $tableName |
|
75 * @param string|Zend_Db_Select $query |
|
76 */ |
|
77 public function addTable($tableName, $query = NULL) |
|
78 { |
|
79 if ($query === NULL) { |
|
80 $query = $this->databaseConnection->getConnection()->select(); |
|
81 $query->from($tableName, Zend_Db_Select::SQL_WILDCARD); |
|
82 } |
|
83 |
|
84 if($query instanceof Zend_Db_Select) { |
|
85 $query = $query->__toString(); |
|
86 } |
|
87 |
|
88 $this->tables[$tableName] = new Zend_Test_PHPUnit_Db_DataSet_QueryTable($tableName, $query, $this->databaseConnection); |
|
89 } |
|
90 } |