PgsqlTest.php 5.9 KB

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