1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Tests\Portability; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Driver\Statement as DriverStatement; |
8
|
|
|
use Doctrine\DBAL\ParameterType; |
9
|
|
|
use Doctrine\DBAL\Portability\Connection; |
10
|
|
|
use Doctrine\DBAL\Portability\Statement; |
11
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use function iterator_to_array; |
14
|
|
|
|
15
|
|
|
class StatementTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** @var Connection|MockObject */ |
18
|
|
|
protected $conn; |
19
|
|
|
|
20
|
|
|
/** @var Statement */ |
21
|
|
|
protected $stmt; |
22
|
|
|
|
23
|
|
|
/** @var DriverStatement|MockObject */ |
24
|
|
|
protected $wrappedStmt; |
25
|
|
|
|
26
|
|
|
protected function setUp() : void |
27
|
|
|
{ |
28
|
|
|
$this->wrappedStmt = $this->createMock(DriverStatement::class); |
29
|
|
|
$this->conn = $this->createConnection(); |
30
|
|
|
$this->stmt = $this->createStatement($this->wrappedStmt, $this->conn); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @group DBAL-726 |
35
|
|
|
*/ |
36
|
|
|
public function testBindParam() : void |
37
|
|
|
{ |
38
|
|
|
$column = 'mycolumn'; |
39
|
|
|
$variable = 'myvalue'; |
40
|
|
|
$type = ParameterType::STRING; |
41
|
|
|
$length = 666; |
42
|
|
|
|
43
|
|
|
$this->wrappedStmt->expects(self::once()) |
44
|
|
|
->method('bindParam') |
45
|
|
|
->with($column, $variable, $type, $length); |
46
|
|
|
|
47
|
|
|
$this->stmt->bindParam($column, $variable, $type, $length); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testBindValue() : void |
51
|
|
|
{ |
52
|
|
|
$param = 'myparam'; |
53
|
|
|
$value = 'myvalue'; |
54
|
|
|
$type = ParameterType::STRING; |
55
|
|
|
|
56
|
|
|
$this->wrappedStmt->expects(self::once()) |
57
|
|
|
->method('bindValue') |
58
|
|
|
->with($param, $value, $type); |
59
|
|
|
|
60
|
|
|
$this->stmt->bindValue($param, $value, $type); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testCloseCursor() : void |
64
|
|
|
{ |
65
|
|
|
$this->wrappedStmt->expects(self::once()) |
66
|
|
|
->method('closeCursor'); |
67
|
|
|
|
68
|
|
|
$this->stmt->closeCursor(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testColumnCount() : void |
72
|
|
|
{ |
73
|
|
|
$columnCount = 666; |
74
|
|
|
|
75
|
|
|
$this->wrappedStmt->expects(self::once()) |
76
|
|
|
->method('columnCount') |
77
|
|
|
->will(self::returnValue($columnCount)); |
78
|
|
|
|
79
|
|
|
self::assertSame($columnCount, $this->stmt->columnCount()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testExecute() : void |
83
|
|
|
{ |
84
|
|
|
$params = [ |
85
|
|
|
'foo', |
86
|
|
|
'bar', |
87
|
|
|
]; |
88
|
|
|
|
89
|
|
|
$this->wrappedStmt->expects(self::once()) |
90
|
|
|
->method('execute') |
91
|
|
|
->with($params); |
92
|
|
|
|
93
|
|
|
$this->stmt->execute($params); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testGetIterator() : void |
97
|
|
|
{ |
98
|
|
|
$this->wrappedStmt->expects(self::exactly(3)) |
99
|
|
|
->method('fetch') |
100
|
|
|
->willReturnOnConsecutiveCalls('foo', 'bar', false); |
101
|
|
|
|
102
|
|
|
self::assertSame(['foo', 'bar'], iterator_to_array($this->stmt->getIterator())); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function testRowCount() : void |
106
|
|
|
{ |
107
|
|
|
$rowCount = 666; |
108
|
|
|
|
109
|
|
|
$this->wrappedStmt->expects(self::once()) |
110
|
|
|
->method('rowCount') |
111
|
|
|
->will(self::returnValue($rowCount)); |
112
|
|
|
|
113
|
|
|
self::assertSame($rowCount, $this->stmt->rowCount()); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return Connection|MockObject |
118
|
|
|
*/ |
119
|
|
|
protected function createConnection() |
120
|
|
|
{ |
121
|
|
|
return $this->getMockBuilder(Connection::class) |
122
|
|
|
->disableOriginalConstructor() |
123
|
|
|
->getMock(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
protected function createStatement(DriverStatement $wrappedStatement, Connection $connection) : Statement |
127
|
|
|
{ |
128
|
|
|
return new Statement($wrappedStatement, $connection); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|