OCI8StatementTest.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace Doctrine\Tests\DBAL;
  3. require_once __DIR__ . '/../../../TestInit.php';
  4. class OCI8StatementTest extends \Doctrine\Tests\DbalTestCase
  5. {
  6. public function setUp()
  7. {
  8. if ( ! extension_loaded('oci8')) {
  9. $this->markTestSkipped();
  10. }
  11. }
  12. protected function getMockOCI8Statement()
  13. {
  14. $dbh = null;
  15. $statement = "update table set field1 = ?, field2 = ? where field3 = ?";
  16. $executeMode = OCI_COMMIT_ON_SUCCESS;
  17. return $this->getMock('\Doctrine\DBAL\Driver\OCI8\OCI8Statement',
  18. array('bindValue', 'errorInfo'),
  19. array(null, $statement, $executeMode), '', false);
  20. }
  21. /**
  22. * This scenario shows that when the first parameter is not null
  23. * it properly sets $hasZeroIndex to 1 and calls bindValue starting at 1.
  24. *
  25. * The expected exception is due to oci_execute failing due to no valid connection.
  26. *
  27. * @dataProvider executeDataProvider
  28. * @expectedException \Doctrine\DBAL\Driver\OCI8\OCI8Exception
  29. */
  30. public function testExecute(array $params)
  31. {
  32. $statement = $this->getMockOCI8Statement();
  33. $statement->expects($this->at(0))
  34. ->method('bindValue')
  35. ->with(
  36. $this->equalTo(1),
  37. $this->equalTo($params[0])
  38. );
  39. $statement->expects($this->at(1))
  40. ->method('bindValue')
  41. ->with(
  42. $this->equalTo(2),
  43. $this->equalTo($params[1])
  44. );
  45. $statement->expects($this->at(2))
  46. ->method('bindValue')
  47. ->with(
  48. $this->equalTo(3),
  49. $this->equalTo($params[2])
  50. );
  51. $statement->execute($params);
  52. }
  53. public static function executeDataProvider()
  54. {
  55. return array(
  56. // $hasZeroIndex = isset($params[0]); == true
  57. array(
  58. array(0 => 'test', 1 => null, 2 => 'value')
  59. ),
  60. // $hasZeroIndex = isset($params[0]); == false
  61. array(
  62. array(0 => null, 1 => 'test', 2 => 'value')
  63. )
  64. );
  65. }
  66. }