Skip to content

Commit 2136d02

Browse files
authored
Merge pull request #1 from MonetDB/ci
Unit Tests and CI
2 parents 8275a3c + 87109cf commit 2136d02

File tree

5 files changed

+181
-0
lines changed

5 files changed

+181
-0
lines changed

.github/workflows/php.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: PHP Composer
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-20.04
8+
env:
9+
DBFARM: /var/lib/monetdb
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Validate composer.json and composer.lock
15+
run: composer validate
16+
17+
- name: Cache Composer packages
18+
id: composer-cache
19+
uses: actions/cache@v2
20+
with:
21+
path: vendor
22+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
23+
restore-keys: |
24+
${{ runner.os }}-php-
25+
26+
- name: Install dependencies
27+
if: steps.composer-cache.outputs.cache-hit != 'true'
28+
run: composer install --prefer-dist --no-progress --no-suggest
29+
30+
- name: Install MonetDB
31+
run: |
32+
sudo apt-get update -qq
33+
sudo apt-get install -y software-properties-common curl make
34+
curl https://www.monetdb.org/downloads/MonetDB-GPG-KEY | sudo apt-key add -
35+
sudo add-apt-repository 'deb http://dev.monetdb.org/downloads/deb/ focal monetdb'
36+
sudo apt-get update -qq
37+
sudo apt-get install -y monetdb5-server
38+
39+
- name: Run MonetDB
40+
run: |
41+
sudo mkdir -p -m 770 ${{ env.DBFARM }}
42+
sudo chown -R monetdb.monetdb ${{ env.DBFARM }}
43+
sudo -u monetdb monetdbd create ${{ env.DBFARM }}
44+
sudo -u monetdb monetdbd set control=yes ${{ env.DBFARM }}
45+
sudo -u monetdb monetdbd set passphrase=testdb ${{ env.DBFARM }}
46+
sudo -u monetdb monetdbd start ${{ env.DBFARM }}
47+
48+
- name: Create database
49+
run: |
50+
sudo -u monetdb monetdb create temp
51+
sudo -u monetdb monetdb release temp
52+
sudo -u monetdb monetdb start temp || true
53+
54+
- name: Run Unit-Tests
55+
run: |
56+
./vendor/bin/phpunit tests/
57+
58+

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,8 @@
2525
"psr-4": {
2626
"MonetDB\\": "src/"
2727
}
28+
},
29+
"require-dev": {
30+
"phpunit/phpunit": "^9"
2831
}
2932
}

tests/dec38Test.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
use PHPUnit\Framework\TestCase;
3+
use MonetDB\Connection;
4+
5+
require_once(__DIR__. '../../src/include.php');
6+
7+
final class dec38Test extends TestCase {
8+
public $conn;
9+
10+
public function setUp(): void
11+
{
12+
$this->conn = new Connection("127.0.0.1", 50000, "monetdb", "monetdb", "temp");
13+
}
14+
15+
public function testBigIntTable(): void
16+
{
17+
$res = $this->conn->Query("CREATE TABLE php_dec38 (d38_0 DECIMAL(38,0), d38_19 DECIMAL(38,19), d38_38 DECIMAL(38,38));");
18+
19+
$this->assertCount(0, $res);
20+
}
21+
22+
public function testInsertBigInt(): void
23+
{
24+
$res = $this->conn->Query("INSERT INTO php_dec38 VALUES (12345678901234567899876543210987654321, 1234567890123456789.9876543210987654321, .12345678901234567899876543210987654321);");
25+
26+
$this->assertCount(0, $res);
27+
}
28+
29+
public function testSelectBigInt(): void
30+
{
31+
$res = $this->conn->Query("SELECT * FROM php_dec38");
32+
$res_arr = iterator_to_array($res);
33+
34+
$this->assertEquals($res_arr[1]["d38_0"], "12345678901234567899876543210987654321");
35+
$this->assertEquals($res_arr[1]["d38_19"], "1234567890123456789.9876543210987654321");
36+
$this->assertEquals($res_arr[1]["d38_38"], "0.12345678901234567899876543210987654321");
37+
}
38+
39+
}
40+
?>

tests/int128Test.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
use PHPUnit\Framework\TestCase;
4+
use MonetDB\Connection;
5+
6+
require_once(__DIR__. '../../src/include.php');
7+
8+
final class int128Test extends TestCase {
9+
public $conn;
10+
11+
public function setUp(): void
12+
{
13+
$this->conn = new Connection("127.0.0.1", 50000, "monetdb", "monetdb", "temp");
14+
}
15+
16+
public function testStartTransaction(): void
17+
{
18+
$res = $this->conn->Query("START TRANSACTION");
19+
20+
$this->assertCount(0, $res);
21+
}
22+
23+
public function testBigIntTable(): void
24+
{
25+
$res = $this->conn->Query("CREATE TABLE php_int128 (i HUGEINT);");
26+
27+
$this->assertCount(0, $res);
28+
}
29+
30+
public function testInsertBigInt(): void
31+
{
32+
$res = $this->conn->Query("INSERT INTO php_int128 VALUES (123456789098765432101234567890987654321);");
33+
34+
$this->assertCount(0, $res);
35+
}
36+
37+
public function testSelectBigInt(): void
38+
{
39+
$res = $this->conn->Query("SELECT * FROM php_int128");
40+
$res_arr = iterator_to_array($res);
41+
42+
$this->assertEquals($res_arr[1]["i"], "123456789098765432101234567890987654321");
43+
}
44+
45+
}
46+
?>

tests/sizeLimitBugTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
use PHPUnit\Framework\TestCase;
3+
use MonetDB\Connection;
4+
5+
require_once(__DIR__. '../../src/include.php');
6+
7+
final class sizeLimitBugTest extends TestCase {
8+
9+
public $packet_size = 20000;
10+
public $conn;
11+
12+
public function setUp(): void
13+
{
14+
$this->conn = new Connection("127.0.0.1", 50000, "monetdb", "monetdb", "temp");
15+
}
16+
17+
public function testWeCanConnectToDatabase(): void
18+
{
19+
$this->assertInstanceOf(
20+
Connection::class,
21+
$this->conn
22+
);
23+
}
24+
25+
public function testWeCanFetchRows(): void
26+
{
27+
$sql = 'select 1';
28+
$sql = str_pad($sql, $this->packet_size , ' ');
29+
30+
$res = $this->conn->Query($sql);
31+
$this->assertCount(1, $res);
32+
}
33+
}
34+
?>

0 commit comments

Comments
 (0)