DbRowsetTest.php 3.5 KB

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