QueryDataSet.php 3.1 KB

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