2
0

MysqliTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. class Zend_Db_Statement_MysqliTest extends Zend_Db_Statement_TestCommon
  24. {
  25. public function testStatementRowCount()
  26. {
  27. $products = $this->_db->quoteIdentifier('zfproducts');
  28. $product_id = $this->_db->quoteIdentifier('product_id');
  29. $stmt = $this->_db->prepare("DELETE FROM $products WHERE $product_id = 1");
  30. $n = $stmt->rowCount();
  31. $this->assertType('integer', $n);
  32. $this->assertEquals(-1, $n, 'Expecting row count to be -1 before executing query');
  33. $stmt->execute();
  34. $n = $stmt->rowCount();
  35. $stmt->closeCursor();
  36. $this->assertType('integer', $n);
  37. $this->assertEquals(1, $n, 'Expected row count to be one after executing query');
  38. }
  39. public function testStatementBindParamByName()
  40. {
  41. $products = $this->_db->quoteIdentifier('zfproducts');
  42. $product_id = $this->_db->quoteIdentifier('product_id');
  43. $product_name = $this->_db->quoteIdentifier('product_name');
  44. $productIdValue = 4;
  45. $productNameValue = 'AmigaOS';
  46. try {
  47. $stmt = $this->_db->prepare("INSERT INTO $products ($product_id, $product_name) VALUES (:id, :name)");
  48. // test with colon prefix
  49. $this->assertTrue($stmt->bindParam(':id', $productIdValue), 'Expected bindParam(\':id\') to return true');
  50. // test with no colon prefix
  51. $this->assertTrue($stmt->bindParam('name', $productNameValue), 'Expected bindParam(\'name\') to return true');
  52. $this->fail('Expected to catch Zend_Db_Statement_Exception');
  53. } catch (Zend_Exception $e) {
  54. $this->assertType('Zend_Db_Statement_Exception', $e,
  55. 'Expecting object of type Zend_Db_Statement_Exception, got '.get_class($e));
  56. $this->assertEquals("Invalid bind-variable name ':id'", $e->getMessage());
  57. }
  58. }
  59. public function testStatementBindValueByName()
  60. {
  61. $products = $this->_db->quoteIdentifier('zfproducts');
  62. $product_id = $this->_db->quoteIdentifier('product_id');
  63. $product_name = $this->_db->quoteIdentifier('product_name');
  64. $productIdValue = 4;
  65. $productNameValue = 'AmigaOS';
  66. try {
  67. $stmt = $this->_db->prepare("INSERT INTO $products ($product_id, $product_name) VALUES (:id, :name)");
  68. // test with colon prefix
  69. $this->assertTrue($stmt->bindParam(':id', $productIdValue), 'Expected bindParam(\':id\') to return true');
  70. // test with no colon prefix
  71. $this->assertTrue($stmt->bindParam('name', $productNameValue), 'Expected bindParam(\'name\') to return true');
  72. $this->fail('Expected to catch Zend_Db_Statement_Exception');
  73. } catch (Zend_Exception $e) {
  74. $this->assertType('Zend_Db_Statement_Exception', $e,
  75. 'Expecting object of type Zend_Db_Statement_Exception, got '.get_class($e));
  76. $this->assertEquals("Invalid bind-variable name ':id'", $e->getMessage());
  77. }
  78. }
  79. public function testStatementGetColumnMeta()
  80. {
  81. $this->markTestIncomplete($this->getDriver() . ' has not implemented getColumnMeta() yet [ZF-1424]');
  82. }
  83. public function getDriver()
  84. {
  85. return 'Mysqli';
  86. }
  87. }