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
75 changes: 75 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:
inputs:
libsql-server-release:
description: 'LibSQL Server Release'
required: false
default: 'libsql-server-v0.24.32'

jobs:
test:
name: Tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

steps:

- uses: actions/checkout@v4

- name: Install sqld
run: |
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/tursodatabase/libsql/releases/download/${{ github.event.inputs.libsql-server-release || 'libsql-server-v0.24.32' }}/libsql-server-installer.sh | sh
echo "$HOME/.sqld/bin" >> $GITHUB_PATH
sqld --version

- name: Start sqld server
run: |
sqld &
while ! curl -s http://localhost:8080/health > /dev/null; do
echo "Waiting for sqld..."
sleep 1
done
echo "sqld is ready!"

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none

- name: Install Composer Dependencies
run: composer install --prefer-dist --no-progress

- name: Run Tests
env:
TURSO_URL: "http://localhost:8080"
TURSO_AUTH_TOKEN: ""
run: vendor/bin/phpunit tests/

test-window:
name: Tests on windows-latest
runs-on: windows-latest
steps:

- uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
extensions: ffi

- name: Install Composer Dependencies
run: composer install --prefer-dist --no-progress

- name: Run Tests
run: vendor/bin/phpunit tests/
63 changes: 49 additions & 14 deletions tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,17 @@ public function testNull(): void

public function testEmbeddedReplica(): void
{
$url = getenv('TURSO_URL');
$authToken = getenv('TURSO_AUTH_TOKEN');

if ($url == false) {
$this->markTestSkipped();
}

$db = new Database(
path: 'test.db',
url: getenv('TURSO_URL'),
authToken: getenv('TURSO_AUTH_TOKEN'),
url: $url,
authToken: $authToken,
syncInterval: 100,
);
$conn = $db->connect();
Expand All @@ -117,16 +124,23 @@ public function testEmbeddedReplica(): void

foreach ($conn->query('select * from test') as $i => $row) {
$this->assertSame($row->i, $i);
$this->assertSame($row->r, exp($i / 10));
$this->assertSame($row->t, strval(exp($i / 10)));
$this->assertLessThanOrEqual(abs($row->r - exp($i / 10)), 0.0e-12);
$this->assertLessThanOrEqual(abs($row->t - strval(exp($i / 10))), 0.0e-12);
}
}

public function testRemoteReplica(): void
{
$url = getenv('TURSO_URL');
$authToken = getenv('TURSO_AUTH_TOKEN');

if ($url == false) {
$this->markTestSkipped();
}

$db = new Database(
url: getenv('TURSO_URL'),
authToken: getenv('TURSO_AUTH_TOKEN'),
url: $url,
authToken: $authToken,
);
$conn = $db->connect();

Expand Down Expand Up @@ -163,11 +177,18 @@ public function testBlob(): void

public function testTransactions(): void
{
$url = getenv('TURSO_URL');
$authToken = getenv('TURSO_AUTH_TOKEN');

if ($url == false) {
$this->markTestSkipped();
}

$db = new Database(
path: 'test.db',
url: getenv('TURSO_URL'),
authToken: getenv('TURSO_AUTH_TOKEN'),
syncInterval: 100,
// path: 'test.db',
url: $url,
authToken: $authToken,
// syncInterval: 100,
);
$conn = $db->connect();

Expand Down Expand Up @@ -200,8 +221,15 @@ public function testStatementColumnCount(): void

public function testPDORemote(): void
{
$pdo = new \Libsql\PDO(password: getenv('TURSO_AUTH_TOKEN'), options: [
'url' => getenv('TURSO_URL'),
$url = getenv('TURSO_URL');
$authToken = getenv('TURSO_AUTH_TOKEN');

if (!$url) {
$this->markTestSkipped();
}

$pdo = new \Libsql\PDO(password: $authToken, options: [
'url' => $url,
]);

$statement = $pdo->prepare('select ?');
Expand All @@ -214,8 +242,15 @@ public function testPDORemote(): void

public function testPDORemoteFetchObj(): void
{
$pdo = new \Libsql\PDO(password: getenv('TURSO_AUTH_TOKEN'), options: [
'url' => getenv('TURSO_URL'),
$url = getenv('TURSO_URL');
$authToken = getenv('TURSO_AUTH_TOKEN');

if ($url == false) {
$this->markTestSkipped();
}

$pdo = new \Libsql\PDO(password: $authToken, options: [
'url' => $url,
]);

$statement = $pdo->prepare('select * from test');
Expand Down