TestCommon.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_Adapter_TestCommon
  24. */
  25. require_once 'Zend/Db/Adapter/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. */
  33. abstract class Zend_Db_Adapter_Pdo_TestCommon extends Zend_Db_Adapter_TestCommon
  34. {
  35. public function testAdapterAlternateStatement()
  36. {
  37. $this->_testAdapterAlternateStatement('Test_PdoStatement');
  38. }
  39. /**
  40. * Ensures that exec() throws an exception when given a bogus query
  41. * @group ZF-6185
  42. * @return void
  43. */
  44. public function testAdapterExecBogus()
  45. {
  46. try {
  47. $this->_db->exec('Bogus query');
  48. $this->fail('Expected exception not thrown');
  49. } catch (Zend_Db_Adapter_Exception $e) {
  50. $this->assertTrue($e instanceof Zend_Db_Adapter_Exception,
  51. 'Expecting object of type Zend_Db_Adapter_Exception, got ' . get_class($e));
  52. }
  53. }
  54. /**
  55. * Ensures that exec() throws an exception when given a bogus table
  56. * @group ZF-6185
  57. * @return void
  58. */
  59. public function testAdapterExecBogusTable()
  60. {
  61. try {
  62. $this->_db->exec('DELETE FROM BogusTable');
  63. $this->fail('Expected exception not thrown');
  64. } catch (Zend_Db_Adapter_Exception $e) {
  65. $this->assertTrue($e instanceof Zend_Db_Adapter_Exception,
  66. 'Expecting object of type Zend_Db_Adapter_Exception, got ' . get_class($e));
  67. }
  68. }
  69. /**
  70. * Ensures that exec() provides expected behavior when modifying no rows
  71. * @group ZF-6185
  72. * @return void
  73. */
  74. public function testAdapterExecModifiedNone()
  75. {
  76. $affected = $this->_db->exec('DELETE FROM ' . $this->_db->quoteIdentifier('zfbugs') . ' WHERE 1 = -1');
  77. $this->assertEquals(0, $affected,
  78. "Expected exec() to return zero affected rows; got $affected");
  79. }
  80. /**
  81. * Test for null byte injection
  82. */
  83. public function testAdapterQuoteNullByteCharacter()
  84. {
  85. $string = "1\0";
  86. $value = $this->_db->quote($string);
  87. $this->assertNotContains("\0", $value);
  88. }
  89. }