2
0

DbTableDataSet.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 $where
  49. * @param string $order
  50. * @param string $count
  51. * @param string $offset
  52. */
  53. public function addTable(Zend_Db_Table_Abstract $table, $where = null, $order = null, $count = null, $offset = null)
  54. {
  55. $tableName = $table->info('name');
  56. $this->tables[$tableName] = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $where, $order, $count, $offset);
  57. }
  58. /**
  59. * Creates an iterator over the tables in the data set. If $reverse is
  60. * true a reverse iterator will be returned.
  61. *
  62. * @param bool $reverse
  63. * @return PHPUnit_Extensions_Database_DB_TableIterator
  64. */
  65. protected function createIterator($reverse = FALSE)
  66. {
  67. return new PHPUnit_Extensions_Database_DataSet_DefaultTableIterator($this->tables, $reverse);
  68. }
  69. /**
  70. * Returns a table object for the given table.
  71. *
  72. * @param string $tableName
  73. * @return PHPUnit_Extensions_Database_DB_Table
  74. */
  75. public function getTable($tableName)
  76. {
  77. if (!isset($this->tables[$tableName])) {
  78. throw new InvalidArgumentException("$tableName is not a table in the current database.");
  79. }
  80. return $this->tables[$tableName];
  81. }
  82. /**
  83. * Returns a list of table names for the database
  84. *
  85. * @return Array
  86. */
  87. public function getTableNames()
  88. {
  89. return array_keys($this->tables);
  90. }
  91. }