DbTable.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-2009 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. require_once "PHPUnit/Extensions/Database/DataSet/QueryTable.php";
  23. /**
  24. * @see Zend_Db_Table_Abstract
  25. */
  26. require_once "Zend/Db/Table/Abstract.php";
  27. /**
  28. * Use a Zend_Db_Table for assertions with other PHPUnit Database Extension table types.
  29. *
  30. * @uses PHPUnit_Extensions_Database_DataSet_QueryTable
  31. * @category Zend
  32. * @package Zend_Test
  33. * @subpackage PHPUnit
  34. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. class Zend_Test_PHPUnit_Db_DataSet_DbTable extends PHPUnit_Extensions_Database_DataSet_QueryTable
  38. {
  39. /**
  40. * Zend_Db_Table object
  41. *
  42. * @var Zend_Db_Table_Abstract
  43. */
  44. protected $_table = null;
  45. /**
  46. * @var array
  47. */
  48. protected $_columns = array();
  49. /**
  50. * @var string
  51. */
  52. protected $_where = null;
  53. /**
  54. * @var string
  55. */
  56. protected $_orderBy = null;
  57. /**
  58. * @var string
  59. */
  60. protected $_count = null;
  61. /**
  62. * @var int
  63. */
  64. protected $_offset = null;
  65. /**
  66. * Construct Dataset Table from Zend_Db_Table object
  67. *
  68. * @param Zend_Db_Table_Abstract $table
  69. * @param string|Zend_Db_Select|null $where
  70. * @param string|null $order
  71. * @param int $count
  72. * @param int $offset
  73. */
  74. public function __construct(Zend_Db_Table_Abstract $table, $where=null, $order=null, $count=null, $offset=null)
  75. {
  76. $this->tableName = $table->info('name');
  77. $this->_columns = $table->info('cols');
  78. $this->_table = $table;
  79. $this->_where = $where;
  80. $this->_order = $order;
  81. $this->_count = $count;
  82. $this->_offset = $offset;
  83. }
  84. /**
  85. * Lazy load data via table fetchAll() method.
  86. *
  87. * @return void
  88. */
  89. protected function loadData()
  90. {
  91. if ($this->data === null) {
  92. $this->data = $this->_table->fetchAll(
  93. $this->_where, $this->_order, $this->_count, $this->_offset
  94. );
  95. if($this->data instanceof Zend_Db_Table_Rowset_Abstract) {
  96. $this->data = $this->data->toArray();
  97. }
  98. }
  99. }
  100. /**
  101. * Create Table Metadata object
  102. */
  103. protected function createTableMetaData()
  104. {
  105. if ($this->tableMetaData === NULL) {
  106. $this->loadData();
  107. $this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $this->_columns);
  108. }
  109. }
  110. }