DbRowset.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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-2015 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_Rowset_Abstract
  24. */
  25. require_once "Zend/Db/Table/Rowset/Abstract.php";
  26. /**
  27. * Use a Zend_Db Rowset as a datatable for assertions with other PHPUnit Database extension tables.
  28. *
  29. * @uses PHPUnit_Extensions_Database_DataSet_AbstractTable
  30. * @category Zend
  31. * @package Zend_Test
  32. * @subpackage PHPUnit
  33. * @copyright Copyright (c) 2005-2015 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_DbRowset extends PHPUnit_Extensions_Database_DataSet_AbstractTable
  37. {
  38. /**
  39. * Construct Table object from a Zend_Db_Table_Rowset
  40. *
  41. * @param Zend_Db_Table_Rowset_Abstract $rowset
  42. * @param string $tableName
  43. */
  44. public function __construct(Zend_Db_Table_Rowset_Abstract $rowset, $tableName = null)
  45. {
  46. if($tableName == null) {
  47. $table = $rowset->getTable();
  48. if($table !== null) {
  49. $tableName = $table->info('name');
  50. } else {
  51. require_once "Zend/Test/PHPUnit/Db/Exception.php";
  52. throw new Zend_Test_PHPUnit_Db_Exception(
  53. 'No table name was given to Rowset Table and table name cannot be infered from the table, '.
  54. 'because the rowset is disconnected from database.'
  55. );
  56. }
  57. }
  58. $this->data = $rowset->toArray();
  59. $columns = array();
  60. if(isset($this->data[0]) > 0) {
  61. $columns = array_keys($this->data[0]);
  62. } else if($rowset->getTable() != null) {
  63. $columns = $rowset->getTable()->info('cols');
  64. }
  65. $this->tableName = $tableName;
  66. $this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $columns);
  67. }
  68. }