Skip to content

Commit f980d42

Browse files
committed
Added sample CI test
1 parent 8c88ee3 commit f980d42

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

.github/workflows/tests.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CI test connection
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main ]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build:
13+
services:
14+
ydb:
15+
image: cr.yandex/yc/yandex-docker-local-ydb:stable-22-5
16+
ports:
17+
- 2135:2135
18+
- 2136:2136
19+
- 8765:8765
20+
volumes:
21+
- /tmp/ydb_certs:/ydb_certs
22+
env:
23+
YDB_USE_IN_MEMORY_PDISKS: true
24+
options: '-h localhost'
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- uses: actions/checkout@v3
29+
name: Checkout
30+
31+
- uses: eWaterCycle/setup-grpc@v5
32+
name: Setup gRPC
33+
with:
34+
grpc-version: 1.51.1
35+
36+
- uses: shivammathur/setup-php@v2
37+
name: Setup PHP
38+
id: php
39+
with:
40+
extensions: grpc
41+
php-version: 7.4
42+
43+
- run: composer validate --strict
44+
name: Validate composer.json and composer.lock
45+
46+
- uses: actions/cache@v3
47+
name: Cache Composer packages
48+
id: composer-cache
49+
50+
with:
51+
path: vendor
52+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
53+
restore-keys: |
54+
${{ runner.os }}-php-
55+
- name: Install dependencies
56+
run: composer install --prefer-dist --no-progress
57+
58+
- name: Run tests
59+
run: ./vendor/bin/phpunit \
60+
--coverage-text \
61+
--whitelist src \
62+
--colors=never \
63+
tests

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* added CI test
12
* added access token authentication
23

34
## 1.5.0 (2023-02-22)

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@
1919
"phpseclib/phpseclib": "^2.0|^3.0",
2020
"psr/log": "^1|^2|^3"
2121
},
22+
"require-dev": {
23+
"phpunit/phpunit": "9.*"
24+
},
2225
"autoload": {
2326
"psr-4": {
2427
"Ydb\\": "protos/Ydb/",
2528
"GPBMetadata\\": "protos/GPBMetadata/",
2629
"YdbPlatform\\Ydb\\": "src/"
2730
}
31+
},
32+
"autoload-dev": {
33+
"psr-4": {
34+
"YdbPlatform\\Ydb\\Test\\": "tests"
35+
}
2836
}
2937
}

tests/RunTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
namespace YdbPlatform\Ydb\Test;
3+
4+
use PHPUnit\Framework\TestCase;
5+
use YdbPlatform\Ydb\Ydb;
6+
use YdbPlatform\Ydb\YdbTable;
7+
8+
class RunTest extends TestCase{
9+
public function testAnonymousConnection(){
10+
$config = [
11+
12+
// Database path
13+
'database' => '/local',
14+
15+
// Database endpoint
16+
'endpoint' => 'localhost:2136',
17+
18+
// Auto discovery (dedicated server only)
19+
'discovery' => false,
20+
21+
// IAM config
22+
'iam_config' => [
23+
'anonymous' => true,
24+
'insecure' => true,
25+
],
26+
];
27+
28+
29+
self::assertEquals(
30+
[1, 6, 1, 2, "TBD"],
31+
$this->getYdbResult($config)
32+
);
33+
34+
}
35+
36+
private function getYdbResult(array $config) : array
37+
{
38+
$ydb = new Ydb($config);
39+
$table = $ydb->table();
40+
41+
$session = $table->session();
42+
43+
$session->createTable(
44+
'episodes',
45+
YdbTable::make()
46+
->addColumn('series_id', 'UINT64')
47+
->addColumn('title', 'UTF8')
48+
->addColumn('episode_id', 'UINT64')
49+
->addColumn('season_id', 'UINT64')
50+
->primaryKey('series_id')
51+
);
52+
53+
$session->transaction(function($session) {
54+
return $session->query('
55+
UPSERT INTO `episodes` (series_id, season_id, episode_id, title)
56+
VALUES (2, 6, 1, "TBD");');
57+
});
58+
59+
$result = $session->query('select `series_id`, `season_id`, `episode_id`, `title` from `episodes`;');
60+
return [$result->rowCount(), $result->rows()[0]["season_id"],
61+
$result->rows()[0]["episode_id"],
62+
$result->rows()[0]["series_id"],
63+
$result->rows()[0]["title"]];
64+
}
65+
}

0 commit comments

Comments
 (0)