|
9 | 9 | use Doctrine\DBAL\Types\Type;
|
10 | 10 | use Doctrine\DBAL\Types\Types;
|
11 | 11 |
|
| 12 | +use function array_map; |
| 13 | +use function assert; |
12 | 14 | use function fopen;
|
13 | 15 | use function fseek;
|
14 |
| -use function ftell; |
15 | 16 | use function fwrite;
|
16 | 17 | use function str_repeat;
|
17 | 18 | use function stream_get_contents;
|
@@ -208,19 +209,36 @@ public function testBindValueResetsStream(): void
|
208 | 209 | }
|
209 | 210 |
|
210 | 211 | $stmt = $this->connection->prepare(
|
211 |
| - "INSERT INTO blob_table(id, clobcolumn, blobcolumn) VALUES (1, 'ignored', ?)", |
| 212 | + "INSERT INTO blob_table(id, clobcolumn, blobcolumn) VALUES (?, 'ignored', ?)", |
212 | 213 | );
|
213 | 214 |
|
214 | 215 | $stream = fopen('php://temp', 'rb+');
|
| 216 | + assert($stream !== false); |
| 217 | + |
215 | 218 | fwrite($stream, 'a test');
|
216 | 219 | fseek($stream, 2);
|
217 |
| - $stmt->bindValue(1, $stream, ParameterType::LARGE_OBJECT); |
| 220 | + $stmt->bindValue(1, 1, ParameterType::INTEGER); |
| 221 | + $stmt->bindValue(2, $stream, ParameterType::LARGE_OBJECT); |
218 | 222 |
|
219 |
| - $stmt->execute(); |
| 223 | + $stmt->executeStatement(); |
220 | 224 |
|
221 |
| - self::assertEquals(2, ftell($stream), 'Resource parameter should be reset to position before execute.'); |
| 225 | + $stmt->bindValue(1, 2, ParameterType::INTEGER); |
| 226 | + $stmt->executeStatement(); |
222 | 227 |
|
223 |
| - $this->assertBlobContains('test'); |
| 228 | + $stmt->bindValue(1, 3, ParameterType::INTEGER); |
| 229 | + $stmt->executeStatement(); |
| 230 | + |
| 231 | + $rows = array_map( |
| 232 | + function (array $row): array { |
| 233 | + $row[0] = $this->connection->convertToPHPValue($row[0], Types::INTEGER); |
| 234 | + $row[1] = $this->connection->convertToPHPValue($row[1], Types::STRING); |
| 235 | + |
| 236 | + return $row; |
| 237 | + }, |
| 238 | + $this->connection->fetchAllNumeric('SELECT id, blobcolumn FROM blob_table'), |
| 239 | + ); |
| 240 | + |
| 241 | + self::assertSame([[1, 'test'], [2, 'test'], [3, 'test']], $rows); |
224 | 242 | }
|
225 | 243 |
|
226 | 244 | private function assertBlobContains(string $text): void
|
|
0 commit comments