PgsqlTest.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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_Db
  17. * @subpackage UnitTests
  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_Db_Table_TestCommon
  24. */
  25. require_once 'Zend/Db/Table/TestCommon.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Db
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Db
  33. * @group Zend_Db_Table
  34. */
  35. class Zend_Db_Table_Pdo_PgsqlTest extends Zend_Db_Table_TestCommon
  36. {
  37. public function getDriver()
  38. {
  39. return 'Pdo_Pgsql';
  40. }
  41. public function testTableInsert()
  42. {
  43. $table = $this->_table['bugs'];
  44. $row = array (
  45. 'bug_description' => 'New bug',
  46. 'bug_status' => 'NEW',
  47. 'created_on' => '2007-04-02',
  48. 'updated_on' => '2007-04-02',
  49. 'reported_by' => 'micky',
  50. 'assigned_to' => 'goofy'
  51. );
  52. $insertResult = $table->insert($row);
  53. $lastInsertId = $this->_db->lastInsertId('zfbugs', 'bug_id');
  54. $lastSequenceId = $this->_db->lastSequenceId('zfbugs_bug_id_seq');
  55. $this->assertEquals($insertResult, $lastInsertId);
  56. $this->assertEquals($insertResult, $lastSequenceId);
  57. $this->assertEquals(5, $lastInsertId);
  58. }
  59. public function testTableInsertPkNull()
  60. {
  61. $table = $this->_table['bugs'];
  62. $row = array (
  63. 'bug_id' => null,
  64. 'bug_description' => 'New bug',
  65. 'bug_status' => 'NEW',
  66. 'created_on' => '2007-04-02',
  67. 'updated_on' => '2007-04-02',
  68. 'reported_by' => 'micky',
  69. 'assigned_to' => 'goofy'
  70. );
  71. $insertResult = $table->insert($row);
  72. $lastInsertId = $this->_db->lastInsertId('zfbugs', 'bug_id');
  73. $lastSequenceId = $this->_db->lastSequenceId('zfbugs_bug_id_seq');
  74. $this->assertEquals($insertResult, $lastInsertId);
  75. $this->assertEquals($insertResult, $lastSequenceId);
  76. $this->assertEquals(5, $lastInsertId);
  77. }
  78. public function testTableInsertSequence()
  79. {
  80. $table = $this->_getTable('My_ZendDbTable_TableProducts',
  81. array(Zend_Db_Table_Abstract::SEQUENCE => 'zfproducts_seq'));
  82. $row = array (
  83. 'product_name' => 'Solaris'
  84. );
  85. $insertResult = $table->insert($row);
  86. $lastInsertId = $this->_db->lastInsertId('zfproducts');
  87. $lastSequenceId = $this->_db->lastSequenceId('zfproducts_seq');
  88. $this->assertEquals($insertResult, $lastInsertId);
  89. $this->assertEquals($insertResult, $lastSequenceId);
  90. $this->assertEquals(4, $insertResult);
  91. }
  92. /**
  93. * Ensures that the schema is null if not specified
  94. *
  95. * @return void
  96. */
  97. public function testTableSchemaNotSetIsNull()
  98. {
  99. $tableInfo = $this->_table['bugs']->info();
  100. $this->assertNull($tableInfo['schema']);
  101. }
  102. /**
  103. * Ensures that the schema is set by the 'schema' constructor configuration directive
  104. *
  105. * @return void
  106. */
  107. public function testTableSchemaSetByConstructorConfigSchema()
  108. {
  109. $schema = 'public';
  110. $config = array(
  111. 'db' => $this->_db,
  112. 'schema' => $schema
  113. );
  114. $table = new My_ZendDbTable_TableBugs($config);
  115. $tableInfo = $table->info();
  116. $this->assertEquals($schema, $tableInfo['schema']);
  117. }
  118. /**
  119. * Ensures that the schema is set by the 'name' constructor configuration directive
  120. *
  121. * @return void
  122. */
  123. public function testTableSchemaSetByConstructorConfigName()
  124. {
  125. $schema = 'public';
  126. $tableName = "$schema.zfbugs";
  127. $config = array(
  128. 'db' => $this->_db,
  129. 'name' => $tableName
  130. );
  131. $table = new My_ZendDbTable_TableBugs($config);
  132. $tableInfo = $table->info();
  133. $this->assertEquals($schema, $tableInfo['schema']);
  134. }
  135. /**
  136. * Ensures that a schema given in the 'name' constructor configuration directive overrides any schema specified
  137. * by the 'schema' constructor configuration directive.
  138. *
  139. * @return void
  140. */
  141. public function testTableSchemaConstructorConfigNameOverridesSchema()
  142. {
  143. $schema = 'public';
  144. $tableName = "$schema.zfbugs";
  145. $config = array(
  146. 'db' => $this->_db,
  147. 'schema' => 'foo',
  148. 'name' => $tableName
  149. );
  150. $table = new My_ZendDbTable_TableBugs($config);
  151. $tableInfo = $table->info();
  152. $this->assertEquals($schema, $tableInfo['schema']);
  153. }
  154. /**
  155. * Ensures that fetchAll() provides expected behavior when the schema is specified
  156. *
  157. * @return void
  158. */
  159. public function testTableFetchAllSchemaSet()
  160. {
  161. $schema = 'public';
  162. $config = array(
  163. 'db' => $this->_db,
  164. 'schema' => $schema,
  165. );
  166. $table = new My_ZendDbTable_TableBugs($config);
  167. $rowset = $table->fetchAll();
  168. $this->assertThat(
  169. $rowset,
  170. $this->isInstanceOf('Zend_Db_Table_Rowset')
  171. );
  172. $this->assertEquals(
  173. 4,
  174. count($rowset)
  175. );
  176. }
  177. }