DbTableDataSet.php 3.0 KB

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