DbRowsetTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 UnitTests
  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. require_once "Zend/Test/PHPUnit/Db/DataSet/DbRowset.php";
  23. require_once "Zend/Db/Table/Rowset.php";
  24. require_once "PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php";
  25. require_once 'Zend/Test/PHPUnit/Db/Exception.php';
  26. require_once 'Zend/Db/Table/Abstract.php';
  27. /**
  28. * @category Zend
  29. * @package Zend_Test
  30. * @subpackage UnitTests
  31. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  32. * @license http://framework.zend.com/license/new-bsd New BSD License
  33. * @group Zend_Test
  34. */
  35. class Zend_Test_PHPUnit_Db_DataSet_DbRowsetTest extends PHPUnit_Framework_TestCase
  36. {
  37. protected function getRowSet()
  38. {
  39. $config = array(
  40. 'rowClass' => 'stdClass',
  41. 'data' => array(array('foo' => 'bar'), array('foo' => 'baz')),
  42. );
  43. $rowset = new Zend_Db_Table_Rowset($config);
  44. return $rowset;
  45. }
  46. public function testRowsetCountInITableRepresentation()
  47. {
  48. $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($this->getRowSet(), "fooTable");
  49. $this->assertEquals(2, $rowsetTable->getRowCount());
  50. }
  51. public function testRowsetGetSpecificValue()
  52. {
  53. $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($this->getRowSet(), "fooTable");
  54. $this->assertEquals("bar", $rowsetTable->getValue(0, "foo"));
  55. }
  56. public function testRowsetGetSpecificRow()
  57. {
  58. $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($this->getRowSet(), "fooTable");
  59. $this->assertEquals(array("foo" => "baz"), $rowsetTable->getRow(1));
  60. }
  61. public function testRowset_ConstructWithDisconnectedRowset_NoTableName_ThrowsException()
  62. {
  63. $this->setExpectedException("Zend_Test_PHPUnit_Db_Exception");
  64. $rowset = $this->getMock('Zend_Db_Table_Rowset_Abstract', array(), array(), '', false);
  65. $rowset->expects($this->once())
  66. ->method('getTable')
  67. ->will($this->returnValue(null));
  68. $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset);
  69. }
  70. public function testRowset_WithNoRows_GetColumnsFromTable()
  71. {
  72. $columns = array("foo", "bar");
  73. $tableMock = $this->getMock('Zend_Db_Table_Abstract', array(), array(), '', false);
  74. $tableMock->expects($this->once())
  75. ->method('info')
  76. ->with($this->equalTo('cols'))
  77. ->will($this->returnValue($columns));
  78. $rowset = $this->getMock('Zend_Db_Table_Rowset_Abstract', array(), array(), '', false);
  79. $rowset->expects($this->exactly(2))
  80. ->method('getTable')
  81. ->will($this->returnValue($tableMock));
  82. $rowset->expects($this->once())
  83. ->method('toArray')
  84. ->will($this->returnValue( array() ));
  85. $rowsetTable = new Zend_Test_PHPUnit_Db_DataSet_DbRowset($rowset, "tableName");
  86. }
  87. }