Connection.php 3.6 KB

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