Skip to content

Commit

Permalink
Test inserting and selecting a small image
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorejb committed Oct 28, 2024
1 parent 7dab79d commit bb167ec
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
29 changes: 27 additions & 2 deletions test/DbTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,31 @@ public function testException(): void
}
}

public function testBlob(): void
{
$db = static::dbProvider();
$img = file_get_contents('test/DevTheorem.png');

$id = $db->insertRow($this->table, [
'name' => 'DevTheorem',
'dob' => '2024-10-24',
'weight' => 0.0,
'is_disabled' => false,
'photo' => $db->makeBinaryParam($img),
])->id;

/** @var array{photo: string|resource} $row */
$row = $db->selectFrom("SELECT photo FROM {$this->table}")
->where(['user_id' => $id])->query()->getFirst();

if ($db->options->binarySelectedAsStream) {
/** @psalm-suppress PossiblyInvalidArgument */
$row['photo'] = stream_get_contents($row['photo']);
}

$this->assertSame(['photo' => $img], $row);
}

public function testIteratorQuery(): void
{
$peachySql = static::dbProvider();
Expand All @@ -124,8 +149,8 @@ public function testIteratorQuery(): void
}

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

$this->assertInstanceOf(\Generator::class, $iterator);
$colValsCompare = [];
Expand Down
Binary file added test/DevTheorem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions test/MssqlDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ private static function createTestTable(PeachySql $db): void
$sql = "
DROP TABLE IF EXISTS Users;
CREATE TABLE Users (
user_id INT PRIMARY KEY IDENTITY(1,1) NOT NULL,
user_id INT PRIMARY KEY IDENTITY NOT NULL,
name NVARCHAR(50) NOT NULL,
dob DATE NOT NULL,
weight FLOAT NOT NULL,
is_disabled BIT NOT NULL,
uuid BINARY(16) NULL
uuid BINARY(16) NULL,
photo VARBINARY(max) NULL
)";

$db->query($sql);
Expand Down
3 changes: 2 additions & 1 deletion test/MysqlDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ private static function createTestTable(PeachySql $db): void
dob DATE NOT NULL,
weight DOUBLE NOT NULL,
is_disabled BOOLEAN NOT NULL,
uuid BINARY(16) NULL
uuid BINARY(16) NULL,
photo BLOB NULL
)";

$db->query("DROP TABLE IF EXISTS Users");
Expand Down
3 changes: 2 additions & 1 deletion test/PgsqlDbTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ private static function createTestTable(PeachySql $db): void
dob DATE NOT NULL,
weight REAL NOT NULL,
is_disabled BOOLEAN NOT NULL,
uuid bytea NULL
uuid bytea NULL,
photo bytea NULL
)";

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

0 comments on commit bb167ec

Please sign in to comment.