DbRowset.php 2.6 KB

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