Skip to content

Commit aebefdd

Browse files
committed
Test inserting and selecting a small image
1 parent dab5d86 commit aebefdd

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

test/DbTestCase.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,31 @@ public function testException(): void
106106
}
107107
}
108108

109+
public function testBlob(): void
110+
{
111+
$db = static::dbProvider();
112+
$img = file_get_contents('test/DevTheorem.png');
113+
114+
$id = $db->insertRow($this->table, [
115+
'name' => 'DevTheorem',
116+
'dob' => '2024-10-24',
117+
'weight' => 0.0,
118+
'is_disabled' => false,
119+
'photo' => $db->makeBinaryParam($img),
120+
])->id;
121+
122+
/** @var array{photo: string|resource} $row */
123+
$row = $db->selectFrom("SELECT photo FROM {$this->table}")
124+
->where(['user_id' => $id])->query()->getFirst();
125+
126+
if ($db->options->binarySelectedAsStream) {
127+
/** @psalm-suppress PossiblyInvalidArgument */
128+
$row['photo'] = stream_get_contents($row['photo']);
129+
}
130+
131+
$this->assertSame(['photo' => $img], $row);
132+
}
133+
109134
public function testIteratorQuery(): void
110135
{
111136
$peachySql = static::dbProvider();
@@ -124,8 +149,8 @@ public function testIteratorQuery(): void
124149
}
125150

126151
$ids = $peachySql->insertRows($this->table, $insertColVals)->ids;
127-
$iterator = $peachySql->selectFrom("SELECT * FROM {$this->table}")
128-
->where(['user_id' => $ids])->query()->getIterator();
152+
$sql = "SELECT user_id, name, dob, weight, is_disabled, uuid FROM {$this->table}";
153+
$iterator = $peachySql->selectFrom($sql)->where(['user_id' => $ids])->query()->getIterator();
129154

130155
$this->assertInstanceOf(\Generator::class, $iterator);
131156
$colValsCompare = [];

test/DevTheorem.png

5.17 KB
Loading

test/MssqlDbTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ private static function createTestTable(PeachySql $db): void
6767
$sql = "
6868
DROP TABLE IF EXISTS Users;
6969
CREATE TABLE Users (
70-
user_id INT PRIMARY KEY IDENTITY(1,1) NOT NULL,
70+
user_id INT PRIMARY KEY IDENTITY NOT NULL,
7171
name NVARCHAR(50) NOT NULL,
7272
dob DATE NOT NULL,
7373
weight FLOAT NOT NULL,
7474
is_disabled BIT NOT NULL,
75-
uuid BINARY(16) NULL
75+
uuid BINARY(16) NULL,
76+
photo VARBINARY(max) NULL
7677
)";
7778

7879
$db->query($sql);

test/MysqlDbTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ private static function createTestTable(PeachySql $db): void
5050
dob DATE NOT NULL,
5151
weight DOUBLE NOT NULL,
5252
is_disabled BOOLEAN NOT NULL,
53-
uuid BINARY(16) NULL
53+
uuid BINARY(16) NULL,
54+
photo BLOB NULL
5455
)";
5556

5657
$db->query("DROP TABLE IF EXISTS Users");

test/PgsqlDbTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ private static function createTestTable(PeachySql $db): void
5656
dob DATE NOT NULL,
5757
weight REAL NOT NULL,
5858
is_disabled BOOLEAN NOT NULL,
59-
uuid bytea NULL
59+
uuid bytea NULL,
60+
photo bytea NULL
6061
)";
6162

6263
$db->query("DROP TABLE IF EXISTS Users");

0 commit comments

Comments
 (0)