DbTableTest.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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-2010 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 dirname(__FILE__)."/../../../../../TestHelper.php";
  23. require_once "Zend/Test/PHPUnit/Db/DataSet/DbTable.php";
  24. require_once "Zend/Db/Table.php";
  25. /**
  26. * @category Zend
  27. * @package Zend_Test
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2010 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_DbTableTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function testLoadDataSetDelegatesWhereLimitOrderBy()
  36. {
  37. $fixtureWhere = "where";
  38. $fixtureLimit = "limit";
  39. $fixtureOffset = "offset";
  40. $fixtureOrderBy = "order";
  41. $table = $this->getMock('Zend_Db_Table', array(), array(), '', false);
  42. $table->expects($this->once())
  43. ->method('fetchAll')
  44. ->with($fixtureWhere, $fixtureOrderBy, $fixtureLimit, $fixtureOffset)
  45. ->will($this->returnValue(array()));
  46. $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table, $fixtureWhere, $fixtureOrderBy, $fixtureLimit, $fixtureOffset);
  47. $count = $dataSet->getRowCount();
  48. }
  49. public function testGetTableMetadata()
  50. {
  51. $fixtureTableName = "foo";
  52. $table = $this->getMock('Zend_Db_Table', array(), array(), '', false);
  53. $table->expects($this->at(0))
  54. ->method('info')
  55. ->with($this->equalTo('name'))
  56. ->will($this->returnValue($fixtureTableName));
  57. $table->expects($this->at(1))
  58. ->method('info')
  59. ->with($this->equalTo('cols'))
  60. ->will($this->returnValue( array("foo", "bar") ));
  61. $table->expects($this->once())
  62. ->method('fetchAll')
  63. ->will($this->returnValue(array( array("foo" => 1, "bar" => 2) )));
  64. $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table);
  65. $this->assertEquals($fixtureTableName, $dataSet->getTableMetaData()->getTableName());
  66. $this->assertEquals(array("foo", "bar"), $dataSet->getTableMetaData()->getColumns());
  67. }
  68. public function testLoadDataOnlyCalledOnce()
  69. {
  70. $table = $this->getMock('Zend_Db_Table', array(), array(), '', false);
  71. $table->expects($this->once())
  72. ->method('fetchAll')
  73. ->will($this->returnValue(array( array("foo" => 1, "bar" => 2) )));
  74. $dataSet = new Zend_Test_PHPUnit_Db_DataSet_DbTable($table);
  75. $dataSet->getRow(0);
  76. $dataSet->getRow(0);
  77. }
  78. }