Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Nov 24, 2024
1 parent 8932340 commit 150fdc7
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions tests/Functional/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;

use function array_map;
use function assert;
use function fopen;
use function fseek;
use function ftell;
use function fwrite;
use function str_repeat;
use function stream_get_contents;
Expand Down Expand Up @@ -208,19 +209,38 @@ public function testBindValueResetsStream(): void
}

$stmt = $this->connection->prepare(
"INSERT INTO blob_table(id, clobcolumn, blobcolumn) VALUES (1, 'ignored', ?)",
"INSERT INTO blob_table(id, clobcolumn, blobcolumn) VALUES (?, 'ignored', ?)",
);

$stream = fopen('php://temp', 'rb+');
assert($stream !== false);

fwrite($stream, 'a test');
fseek($stream, 2);
$stmt->bindValue(1, $stream, ParameterType::LARGE_OBJECT);
$stmt->bindValue(1, 1, ParameterType::INTEGER);
$stmt->bindValue(2, $stream, ParameterType::LARGE_OBJECT);

$stmt->execute();
$stmt->executeStatement();

self::assertEquals(2, ftell($stream), 'Resource parameter should be reset to position before execute.');
$stmt->bindValue(1, 2, ParameterType::INTEGER);
$stmt->executeStatement();

$this->assertBlobContains('test');
$stmt->bindValue(1, 3, ParameterType::INTEGER);
$stmt->executeStatement();

$rows = array_map(
function (array $row): array {
$resource = $this->connection->convertToPHPValue($row[1], Types::BLOB);

self::assertIsResource($resource);
$row[1] = stream_get_contents($resource);

return $row;
},
$this->connection->fetchAllNumeric('SELECT id, blobcolumn FROM blob_table'),
);

self::assertSame([[1, 'test'], [2, 'test'], [3, 'test']], $rows);
}

private function assertBlobContains(string $text): void
Expand Down

0 comments on commit 150fdc7

Please sign in to comment.