DbAdapterTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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-2009 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/DbAdapter.php";
  24. require_once "Zend/Test/DbStatement.php";
  25. /**
  26. * @category Zend
  27. * @package Zend_Test
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Test_DbAdapterTest extends PHPUnit_Framework_TestCase
  33. {
  34. /**
  35. * @var Zend_Test_DbAdapter
  36. */
  37. private $_adapter = null;
  38. public function setUp()
  39. {
  40. $this->_adapter = new Zend_Test_DbAdapter();
  41. }
  42. public function testAppendStatementToStack()
  43. {
  44. $stmt1 = Zend_Test_DbStatement::createSelectStatement( array() );
  45. $this->_adapter->appendStatementToStack($stmt1);
  46. $stmt2 = Zend_Test_DbStatement::createSelectStatement( array() );
  47. $this->_adapter->appendStatementToStack($stmt2);
  48. $this->assertSame($stmt2, $this->_adapter->query("foo"));
  49. $this->assertSame($stmt1, $this->_adapter->query("foo"));
  50. }
  51. public function testAppendLastInsertId()
  52. {
  53. $this->_adapter->appendLastInsertIdToStack(1);
  54. $this->_adapter->appendLastInsertIdToStack(2);
  55. $this->assertEquals(2, $this->_adapter->lastInsertId());
  56. $this->assertEquals(1, $this->_adapter->lastInsertId());
  57. }
  58. public function testLastInsertIdDefault()
  59. {
  60. $this->assertFalse($this->_adapter->lastInsertId());
  61. }
  62. public function testListTablesDefault()
  63. {
  64. $this->assertEquals(array(), $this->_adapter->listTables());
  65. }
  66. public function testSetListTables()
  67. {
  68. $this->_adapter->setListTables(array("foo", "bar"));
  69. $this->assertEquals(array("foo", "bar"), $this->_adapter->listTables());
  70. }
  71. public function testDescribeTableDefault()
  72. {
  73. $this->assertEquals(array(), $this->_adapter->describeTable("foo"));
  74. }
  75. public function testDescribeTable()
  76. {
  77. $this->_adapter->setDescribeTable("foo", array("bar"));
  78. $this->assertEquals(array("bar"), $this->_adapter->describeTable("foo"));
  79. }
  80. public function testConnect()
  81. {
  82. $this->assertFalse($this->_adapter->isConnected());
  83. $this->_adapter->query("foo");
  84. $this->assertTrue($this->_adapter->isConnected());
  85. $this->_adapter->closeConnection();
  86. $this->assertFalse($this->_adapter->isConnected());
  87. }
  88. public function testAppendLimitToSql()
  89. {
  90. $sql = $this->_adapter->limit("foo", 10, 20);
  91. $this->assertEquals(
  92. "foo LIMIT 20,10", $sql
  93. );
  94. }
  95. }