/zf/library/Zend/Test/PHPUnit/Db/Connection.php

http://github.com/eryx/php-framework-benchmark · PHP · 149 lines · 42 code · 13 blank · 94 comment · 1 complexity · 3271a25e15e3e56ebdd1f0234d80444f MD5 · raw file

  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 PHPUnit
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Connection.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * @see PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
  24. */
  25. require_once "PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php";
  26. /**
  27. * @see Zend_Test_PHPUnit_Db_DataSet_QueryTable
  28. */
  29. require_once "Zend/Test/PHPUnit/Db/DataSet/QueryTable.php";
  30. /**
  31. * @see Zend_Test_PHPUnit_Db_Metadata_Generic
  32. */
  33. require_once "Zend/Test/PHPUnit/Db/Metadata/Generic.php";
  34. /**
  35. * Generic Abstraction of Zend_Db Connections in the PHPUnit Database Extension context.
  36. *
  37. * @uses Zend_Db_Adapter_Abstract
  38. * @uses PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
  39. * @category Zend
  40. * @package Zend_Test
  41. * @subpackage PHPUnit
  42. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  43. * @license http://framework.zend.com/license/new-bsd New BSD License
  44. */
  45. class Zend_Test_PHPUnit_Db_Connection extends PHPUnit_Extensions_Database_DB_DefaultDatabaseConnection
  46. {
  47. /**
  48. * Zend_Db_Adapter_Abstract
  49. *
  50. * @var Zend_Db_Adapter_Abstract
  51. */
  52. protected $_connection;
  53. /**
  54. * Database Schema
  55. *
  56. * @var string $db
  57. */
  58. protected $_schema;
  59. /**
  60. * Metadata
  61. *
  62. * @param PHPUnit_Extensions_Database_DB_IMetaData $db
  63. */
  64. protected $_metaData;
  65. /**
  66. * Construct Connection based on Zend_Db_Adapter_Abstract
  67. *
  68. * @param Zend_Db_Adapter_Abstract $db
  69. * @param string $schema
  70. */
  71. public function __construct(Zend_Db_Adapter_Abstract $db, $schema)
  72. {
  73. $this->_connection = $db;
  74. $this->_schema = $schema;
  75. }
  76. /**
  77. * Close this connection.
  78. *
  79. * @return void
  80. */
  81. public function close()
  82. {
  83. $this->_connection->closeConnection();
  84. }
  85. /**
  86. * Creates a table with the result of the specified SQL statement.
  87. *
  88. * @param string $resultName
  89. * @param string $sql
  90. * @return PHPUnit_Extensions_Database_DataSet_ITable
  91. */
  92. public function createQueryTable($resultName, $sql)
  93. {
  94. return new Zend_Test_PHPUnit_Db_DataSet_QueryTable($resultName, $sql, $this);
  95. }
  96. /**
  97. * Returns a Zend_Db Connection
  98. *
  99. * @return Zend_Db_Adapter_Abstract
  100. */
  101. public function getConnection()
  102. {
  103. return $this->_connection;
  104. }
  105. /**
  106. * Returns a database metadata object that can be used to retrieve table
  107. * meta data from the database.
  108. *
  109. * @return PHPUnit_Extensions_Database_DB_IMetaData
  110. */
  111. public function getMetaData()
  112. {
  113. if($this->_metaData === null) {
  114. $this->_metaData = new Zend_Test_PHPUnit_Db_Metadata_Generic($this->getConnection(), $this->getSchema());
  115. }
  116. return $this->_metaData;
  117. }
  118. /**
  119. * Returns the schema for the connection.
  120. *
  121. * @return string
  122. */
  123. public function getSchema()
  124. {
  125. return $this->_schema;
  126. }
  127. /**
  128. * Returns the command used to truncate a table.
  129. *
  130. * @return string
  131. */
  132. public function getTruncateCommand()
  133. {
  134. return "DELETE";
  135. }
  136. }