2
0

DbRowsetTest.php 3.5 KB

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