TestCommon.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. require_once 'Zend/Db/Statement/TestCommon.php';
  22. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  23. abstract class Zend_Db_Statement_Pdo_TestCommon extends Zend_Db_Statement_TestCommon
  24. {
  25. public function testStatementConstruct()
  26. {
  27. $select = $this->_db->select()
  28. ->from('zfproducts');
  29. $sql = $select->__toString();
  30. $stmt = new Zend_Db_Statement_Pdo($this->_db, $sql);
  31. $this->assertType('Zend_Db_Statement_Pdo', $stmt);
  32. $stmt->closeCursor();
  33. }
  34. public function testStatementConstructWithSelectObject()
  35. {
  36. $select = $this->_db->select()
  37. ->from('zfproducts');
  38. $stmt = new Zend_Db_Statement_Pdo($this->_db, $select);
  39. $this->assertType('Zend_Db_Statement_Interface', $stmt);
  40. $stmt->closeCursor();
  41. }
  42. public function testStatementNextRowset()
  43. {
  44. $select = $this->_db->select()
  45. ->from('zfproducts');
  46. $stmt = $this->_db->prepare($select->__toString());
  47. try {
  48. $stmt->nextRowset();
  49. $this->fail('Expected to catch Zend_Db_Statement_Exception');
  50. } catch (Zend_Exception $e) {
  51. $this->assertType('Zend_Db_Statement_Exception', $e,
  52. 'Expecting object of type Zend_Db_Statement_Exception, got '.get_class($e));
  53. $this->assertEquals('SQLSTATE[IM001]: Driver does not support this function: driver does not support multiple rowsets', $e->getMessage());
  54. }
  55. $stmt->closeCursor();
  56. }
  57. /**
  58. * @group ZF-4486
  59. */
  60. public function testStatementIsIterableThroughtForeach()
  61. {
  62. $select = $this->_db->select()->from('zfproducts');
  63. $stmt = $this->_db->query($select);
  64. $stmt->setFetchMode(Zend_Db::FETCH_OBJ);
  65. foreach ($stmt as $test) {
  66. $this->assertTrue($test instanceof stdClass);
  67. }
  68. $this->assertType('int', iterator_count($stmt));
  69. }
  70. }