1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Driver\OCI8; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Driver\OCI8\OCI8Exception; |
6
|
|
|
use Doctrine\DBAL\Driver\OCI8\OCI8Statement; |
7
|
|
|
use Doctrine\Tests\DbalTestCase; |
8
|
|
|
use function extension_loaded; |
9
|
|
|
|
10
|
|
|
class OCI8StatementTest extends DbalTestCase |
11
|
|
|
{ |
12
|
|
|
protected function setUp() |
13
|
|
|
{ |
14
|
|
|
if (!extension_loaded('oci8')) { |
15
|
|
|
$this->markTestSkipped('oci8 is not installed.'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
parent::setUp(); |
19
|
|
|
} |
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
|
|
|
* This also verifies that the statement will check with the connection to |
26
|
|
|
* see what the current execution mode is. |
27
|
|
|
* |
28
|
|
|
* The expected exception is due to oci_execute failing due to no valid connection. |
29
|
|
|
* |
30
|
|
|
* @dataProvider executeDataProvider |
31
|
|
|
* @expectedException \Doctrine\DBAL\Driver\OCI8\OCI8Exception |
32
|
|
|
*/ |
33
|
|
|
public function testExecute(array $params) |
34
|
|
|
{ |
35
|
|
|
$statement = $this->getMockBuilder('\Doctrine\DBAL\Driver\OCI8\OCI8Statement') |
36
|
|
|
->setMethods(array('bindValue', 'errorInfo')) |
37
|
|
|
->disableOriginalConstructor() |
38
|
|
|
->getMock(); |
39
|
|
|
|
40
|
|
|
$statement->expects($this->at(0)) |
41
|
|
|
->method('bindValue') |
42
|
|
|
->with( |
43
|
|
|
$this->equalTo(1), |
44
|
|
|
$this->equalTo($params[0]) |
45
|
|
|
); |
46
|
|
|
$statement->expects($this->at(1)) |
47
|
|
|
->method('bindValue') |
48
|
|
|
->with( |
49
|
|
|
$this->equalTo(2), |
50
|
|
|
$this->equalTo($params[1]) |
51
|
|
|
); |
52
|
|
|
$statement->expects($this->at(2)) |
53
|
|
|
->method('bindValue') |
54
|
|
|
->with( |
55
|
|
|
$this->equalTo(3), |
56
|
|
|
$this->equalTo($params[2]) |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
// can't pass to constructor since we don't have a real database handle, |
60
|
|
|
// but execute must check the connection for the executeMode |
61
|
|
|
$conn = $this->getMockBuilder('\Doctrine\DBAL\Driver\OCI8\OCI8Connection') |
62
|
|
|
->setMethods(array('getExecuteMode')) |
63
|
|
|
->disableOriginalConstructor() |
64
|
|
|
->getMock(); |
65
|
|
|
$conn->expects($this->once()) |
66
|
|
|
->method('getExecuteMode'); |
67
|
|
|
|
68
|
|
|
$reflProperty = new \ReflectionProperty($statement, '_conn'); |
69
|
|
|
$reflProperty->setAccessible(true); |
70
|
|
|
$reflProperty->setValue($statement, $conn); |
71
|
|
|
|
72
|
|
|
$statement->execute($params); |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public static function executeDataProvider() |
76
|
|
|
{ |
77
|
|
|
return array( |
78
|
|
|
// $hasZeroIndex = isset($params[0]); == true |
|
|
|
|
79
|
|
|
array( |
80
|
|
|
array(0 => 'test', 1 => null, 2 => 'value') |
81
|
|
|
), |
82
|
|
|
// $hasZeroIndex = isset($params[0]); == false |
|
|
|
|
83
|
|
|
array( |
84
|
|
|
array(0 => null, 1 => 'test', 2 => 'value') |
85
|
|
|
) |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @dataProvider nonTerminatedLiteralProvider |
91
|
|
|
*/ |
92
|
|
|
public function testConvertNonTerminatedLiteral($sql, $message) |
93
|
|
|
{ |
94
|
|
|
$this->expectException(OCI8Exception::class); |
95
|
|
|
$this->expectExceptionMessageRegExp($message); |
96
|
|
|
OCI8Statement::convertPositionalToNamedPlaceholders($sql); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public static function nonTerminatedLiteralProvider() |
100
|
|
|
{ |
101
|
|
|
return array( |
102
|
|
|
'no-matching-quote' => array( |
103
|
|
|
"SELECT 'literal FROM DUAL", |
104
|
|
|
'/offset 7/', |
105
|
|
|
), |
106
|
|
|
'no-matching-double-quote' => array( |
107
|
|
|
'SELECT 1 "COL1 FROM DUAL', |
108
|
|
|
'/offset 9/', |
109
|
|
|
), |
110
|
|
|
'incorrect-escaping-syntax' => array( |
111
|
|
|
"SELECT 'quoted \\'string' FROM DUAL", |
112
|
|
|
'/offset 23/', |
113
|
|
|
), |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.