DbRowset.php 2.6 KB

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