PageRenderTime 46ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/unsupported/tests/oracle8_9/ezSQL_oracleTNSTest_.php

http://github.com/jv2222/ezSQL
PHP | 262 lines | 194 code | 21 blank | 47 comment | 3 complexity | 00bf5b60520a45c308a5970ed4be50ac MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. require_once('ez_sql_loader.php');
  3. require 'vendor/autoload.php';
  4. use PHPUnit\Framework\TestCase;
  5. /**
  6. * Test class for ezSQL_oracleTNS.
  7. * Desc..: Oracle TNS component (part of ezSQL databse abstraction library)
  8. *
  9. * @author Justin Vincent (jv@jvmultimedia.com)
  10. * @author Stefanie Janine Stoelting (mail@stefanie-stoelting.de)
  11. * @link http://twitter.com/justinvincent
  12. * @name ezSQL_oracleTNSTest
  13. * @package ezSQL
  14. * @subpackage Tests
  15. * @license FREE / Donation (LGPL - You may do what you like with ezSQL - no exceptions.)
  16. */
  17. class ezSQL_oracleTNSTest extends TestCase {
  18. /**
  19. * @var ezSQL_oracleTNS
  20. */
  21. protected $object;
  22. private $errors;
  23. function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) {
  24. $this->errors[] = compact("errno", "errstr", "errfile",
  25. "errline", "errcontext");
  26. }
  27. function assertError($errstr, $errno) {
  28. foreach ($this->errors as $error) {
  29. if ($error["errstr"] === $errstr
  30. && $error["errno"] === $errno) {
  31. return;
  32. }
  33. }
  34. $this->fail("Error with level " . $errno .
  35. " and message '" . $errstr . "' not found in ",
  36. var_export($this->errors, TRUE));
  37. }
  38. /**
  39. * The connection parameters for the Oracle DB connection
  40. * @var array
  41. */
  42. private $oraConnectionParamsTestConnection = array(
  43. 'User' => 'CMP',
  44. 'Password' => 'cmp',
  45. 'Host' => 'en-yoda-1',
  46. 'Port' => '1521',
  47. 'SessionName' => 'ppisa.febi.bilstein.local',
  48. 'TNS' => 'AL32UTF8'
  49. );
  50. private $sequenceName = 'UNITTEST_ORATNS';
  51. /**
  52. * Sets up the fixture, for example, opens a network connection.
  53. * This method is called before a test is executed.
  54. */
  55. protected function setUp() {
  56. if (!extension_loaded('oci8_12c')) {
  57. $this->markTestSkipped(
  58. 'The Oracle OCI Lib is not available.'
  59. );
  60. }
  61. $this->object = new ezSQL_oracleTNS(
  62. $this->oraConnectionParamsTestConnection['Host'],
  63. $this->oraConnectionParamsTestConnection['Port'],
  64. $this->oraConnectionParamsTestConnection['SessionName'],
  65. $this->oraConnectionParamsTestConnection['User'],
  66. $this->oraConnectionParamsTestConnection['Password'],
  67. $this->oraConnectionParamsTestConnection['TNS']
  68. );
  69. // Create the sequence
  70. $sql = 'CREATE SEQUENCE ' . $this->sequenceName;
  71. $this->object->query($sql);
  72. } // setUp
  73. /**
  74. * Tears down the fixture, for example, closes a network connection.
  75. * This method is called after a test is executed.
  76. */
  77. protected function tearDown() {
  78. // Drop the sequence
  79. //$sql = 'DROP SEQUENCE ' . $this->sequenceName;
  80. //$this->object->query($sql);
  81. $this->object = null;
  82. } // tearDown
  83. /**
  84. * @covers ezSQL_oracleTNS::connect
  85. */
  86. public function testConnect() {
  87. $this->object->connect(
  88. $this->oraConnectionParamsTestConnection['User'],
  89. $this->oraConnectionParamsTestConnection['Password']
  90. );
  91. $this->assertTrue($this->object->isConnected());
  92. } // testConnect
  93. /**
  94. * To test connection pooling with oci_pconnect instead of oci_connect
  95. * @covers ezSQL_oracleTNS::connect
  96. */
  97. public function testPConnect() {
  98. $this->object = null;
  99. $this->object = new ezSQL_oracleTNS(
  100. $this->oraConnectionParamsTestConnection['Host'],
  101. $this->oraConnectionParamsTestConnection['Port'],
  102. $this->oraConnectionParamsTestConnection['SessionName'],
  103. $this->oraConnectionParamsTestConnection['User'],
  104. $this->oraConnectionParamsTestConnection['Password'],
  105. $this->oraConnectionParamsTestConnection['TNS'],
  106. true
  107. );
  108. $this->object->connect(
  109. $this->oraConnectionParamsTestConnection['User'],
  110. $this->oraConnectionParamsTestConnection['Password']
  111. );
  112. $this->assertTrue($this->object->isConnected());
  113. $sql = 'SELECT 5*5 AS TEST_RESULT FROM DUAL';
  114. $recordset = $this->object->query($sql);
  115. $this->assertEquals(1, $recordset);
  116. } // testPConnect
  117. /**
  118. * @covers ezSQL_oracleTNS::quick_connect
  119. */
  120. public function testQuick_connect() {
  121. $this->object->quick_connect(
  122. $this->oraConnectionParamsTestConnection['User'],
  123. $this->oraConnectionParamsTestConnection['Password']
  124. );
  125. $this->assertTrue(true);
  126. } // testQuick_connect
  127. /**
  128. * @covers ezSQL_oracleTNS::select
  129. */
  130. public function testSelect() {
  131. $this->object->select(
  132. $this->oraConnectionParamsTestConnection['User'],
  133. $this->oraConnectionParamsTestConnection['Password']
  134. );
  135. $this->assertTrue(true);
  136. } // testSelect
  137. /**
  138. * @covers ezSQL_oracleTNS::escape
  139. */
  140. public function testEscape() {
  141. $result = $this->object->escape("This is'nt escaped.");
  142. $this->assertEquals("This is''nt escaped.", $result);
  143. } // testEscape
  144. /**
  145. * @covers ezSQL_oracleTNS::sysdate
  146. */
  147. public function testSysdate() {
  148. $this->assertEquals('SYSDATE', $this->object->sysdate());
  149. } // testSysdate
  150. /**
  151. * @covers ezSQL_oracleTNS::is_equal_str
  152. */
  153. public function testIs_equal_str() {
  154. $expected = '= \'ezTest string\'';
  155. $this->assertEquals($expected, $this->object->is_equal_str('ezTest string'));
  156. } // testIs_equal_str
  157. /**
  158. * @covers ezSQL_oracleTNS::is_equal_int
  159. */
  160. public function testIs_equal_int() {
  161. $expected = '= 123';
  162. $this->assertEquals($expected, $this->object->is_equal_int(123));
  163. } // testIs_equal_int
  164. /**
  165. * @covers ezSQL_oracleTNS::insert_id
  166. */
  167. public function testInsert_id() {
  168. $this->object->connect(
  169. $this->oraConnectionParamsTestConnection['User'],
  170. $this->oraConnectionParamsTestConnection['Password']
  171. );
  172. $result = $this->object->insert_id($this->sequenceName);
  173. $this->assertEquals(1, $result);
  174. $result = $this->object->insert_id($this->sequenceName);
  175. $this->assertEquals(2, $result);
  176. } // testInsert_id
  177. /**
  178. * @covers ezSQL_oracleTNS::nextVal
  179. */
  180. public function testNextVal() {
  181. $this->object->connect(
  182. $this->oraConnectionParamsTestConnection['User'],
  183. $this->oraConnectionParamsTestConnection['Password']
  184. );
  185. $result = $this->object->nextVal($this->sequenceName);
  186. $this->assertEquals(1, $result);
  187. $result = $this->object->nextVal($this->sequenceName);
  188. $this->assertEquals(2, $result);
  189. } // testNextVal
  190. /**
  191. * @covers ezSQL_oracleTNS::query
  192. */
  193. public function testQuery() {
  194. $this->object->connect(
  195. $this->oraConnectionParamsTestConnection['User'],
  196. $this->oraConnectionParamsTestConnection['Password']
  197. );
  198. $sql = 'SELECT 5*5 AS TEST_RESULT FROM DUAL';
  199. $recordset = $this->object->query($sql);
  200. $this->assertEquals(1, $recordset);
  201. } // testQuery
  202. /**
  203. * @covers ezSQL_oracleTNS::disconnect
  204. */
  205. public function testDisconnect() {
  206. $this->object->disconnect();
  207. $this->assertFalse($this->object->isConnected());
  208. } // testDisconnect
  209. /**
  210. * @covers ezSQL_oracleTNS::__construct
  211. */
  212. public function test__Construct() {
  213. $oracle = $this->getMockBuilder(ezSQL_oracleTNS::class)
  214. ->setMethods(null)
  215. ->disableOriginalConstructor()
  216. ->getMock();
  217. $this->assertNull($oracle->__construct());
  218. }
  219. } // ezSQL_oracleTNSTest