DbTable.php 3.3 KB

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