PgsqlTest.php 6.0 KB

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