DbTable.php 3.2 KB

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