Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/LitebasePDO.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Litebase;

use Composer\InstalledVersions;
use PDO;
use PDO\Sqlite;
use PDOStatement;
Expand Down Expand Up @@ -68,8 +69,8 @@ public function exec(string $statement): int|false
public function getAttribute(int $attribute): mixed
{
return match ($attribute) {
PDO::ATTR_SERVER_VERSION => '0.0.0',
PDO::ATTR_CLIENT_VERSION => '0.0.0',
PDO::ATTR_SERVER_VERSION => $this->getClientVersion(),
PDO::ATTR_CLIENT_VERSION => $this->getClientVersion(),
default => null,
};
}
Expand All @@ -82,6 +83,14 @@ public function getClient(): LitebaseClient
return $this->client;
}

/**
* Return the client version.
*/
protected function getClientVersion(): string
{
return InstalledVersions::getPrettyVersion('litebase/litebase-php') ?? '0.0.0';
}

/**
* Determie if the connection has an error.
*/
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/LitebasePDOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Litebase\LitebaseStatement;
use Litebase\QueryResult;
use Mockery;
use PDO;

test('it can be created', function () {
$pdo = new LitebasePDO(
Expand Down Expand Up @@ -136,6 +137,18 @@
expect($pdo->getClient())->toBeInstanceOf(LitebaseClient::class);
});

test('it returns the client version from composer', function () {
$client = Mockery::mock(LitebaseClient::class);
$pdo = createPDO($client);

$clientVersion = $pdo->getAttribute(PDO::ATTR_CLIENT_VERSION);
$serverVersion = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION);

expect($clientVersion)->toBeString();
expect($clientVersion)->not->toBeEmpty();
expect($serverVersion)->toEqual($clientVersion);
});

function createPDO(LitebaseClient $client): LitebasePDO
{
return new LitebasePDO($client);
Expand Down